我使用最新版本的TLSharp编译了我的控制台测试应用程序,现在我在调用ConnectAsync函数时在DeserializeObject函数行24中遇到异常。据我所知,从某个时刻调试到函数TLContext.getType(Constructor),传递值为-1704251862。这是TLConfig对象的旧构造函数值,我完全无法理解应用程序从何处获取它。在TLSharp库的源中,此值不存在。我重新创建了session.dat文件,但它没有帮助。 Plesase,帮助我,因为我现在的项目现在遇到了大麻烦。这是我的代码:
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());
}
这是例外:&#34;构造函数无效或Context.Init未调用!&#34;。 的 UPD 我想补充一点,将TLSharp升级到66级后出现此问题。
答案 0 :(得分:0)
尝试使用FakeSessionStore而不是FileSessionStore。也许你的程序从文件中获取值。
答案 1 :(得分:0)
我从输出文件夹中删除了“ session.dat”,并解决了该问题。