0
我使用最新版本的TLSharp編譯了我的控制檯測試應用程序,現在我在調用ConnectAsync函數時在DeserializeObject函數行24中出現異常。據我瞭解,從某些時候調試函數TLContext.getType(構造函數)值-1704251862被傳遞。這是TLConfig對象的舊構造器值,我完全無法理解應用程序從何處獲取它。在TLSharp庫的源中,這個值不存在。我重新創建了session.dat文件,但它沒有幫助。 Plesase,幫助我,因爲我目前的項目現在陷入了很大的麻煩。這是我的代碼:函數中的TLSharp異常ConnectAsync
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());
}
而這是例外:「構造函數無效或Context.Init未調用!」。 UPD 我想補充一點,這個問題出現後升級到TLSharp水平66
這將有助於您發佈錯誤消息和調用代碼。 –
我添加了我的代碼和例外描述 – Hermann