I compiled my console test application using latest version of TLSharp and now I have got exception in DeserializeObject function line 24 while calling ConnectAsync function. As far as I understand from debugging in some moment to the function TLContext.getType(Constructor) the value -1704251862 is passed. This is old Constructor value for TLConfig object and I completely can not understand where application get it from. In sources of the TLSharp library this value is absent. I recreated session.dat file but it didn’t help. Plesase, help me, because my current project in big trouble now. This is my code:
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using TeleSharp.TL;
using TeleSharp.TL.Messages;
using TLSharp.Core;
namespace SendPhotoTest
{
public class GetPhotoTester
{
FileSessionStore _sessionStore = new FileSessionStore();
static string registeredPhone = "+7985XXXXXXX";
static int apiID = XXXXX;
static string apiHash = "49d60ed8bd78533986e05e3ffb60b443";
static string code = "XXXXX";
TelegramClient client;
class Assert
{
static internal void IsNotNull(object obj)
{
IsNotNullHanlder(obj);
}
static internal void IsTrue(bool cond)
{
IsTrueHandler(cond);
}
}
internal static Action<object> IsNotNullHanlder;
internal static Action<bool> IsTrueHandler;
protected void Init(Action<object> notNullHandler, Action<bool> trueHandler)
{
IsNotNullHanlder = notNullHandler;
IsTrueHandler = trueHandler;
// Setup your API settings and phone numbers in app.config
//GatherTestConfiguration();
}
public GetPhotoTester()
{
client = CreateClient();
InitializeAndAuthenticateClient(client, 0).Wait();
}
public TelegramClient CreateClient()
{
TelegramClient clt = null;
//clt = new TelegramClient(apiID, apiHash, _sessionStore, "C:\Users\hermann\Documents\session.dat");
clt = new TelegramClient(apiID, apiHash);
return clt;
}
public async Task InitializeAndAuthenticateClient(TelegramClient client, int mode = 1)
{
await client.ConnectAsync();
var hash = await client.SendCodeRequestAsync(registeredPhone);
if (String.IsNullOrWhiteSpace(code))
{
throw new Exception("CodeToAuthenticate is empty in the app.config file, fill it with the code you just got now by SMS/Telegram");
}
TLUser user = null;
try
{
user = await client.MakeAuthAsync(registeredPhone, hash, code);
}
catch (CloudPasswordNeededException ex)
{
var password = await client.GetPasswordSetting();
var password_str = "PasswordToAuthenticate";
user = await client.MakeAuthWithPasswordAsync(password, password_str);
}
catch (InvalidPhoneCodeException ex)
{
throw new Exception("CodeToAuthenticate is wrong in the app.config file, fill it with the code you just got now by SMS/Telegram",
ex);
}
Assert.IsNotNull(user);
Assert.IsTrue(client.IsUserAuthorized());
}
And this is exception: “Constructor Invalid Or Context.Init Not Called !”.
UPD
I’d like to add that this problem appeared after upgrade TLSharp to level 66.
2
Answers
Try to use a FakeSessionStore not FileSessionStore. Maybe your program takes the values from the file.
I removed the “session.dat” from output folder and it fixed the issue.