Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 函数ConnectAsync中存在TLSharp异常_C#_Telegram - Fatal编程技术网

C# 函数ConnectAsync中存在TLSharp异常

C# 函数ConnectAsync中存在TLSharp异常,c#,telegram,C#,Telegram,我使用最新版本的TLSharp编译了我的控制台测试应用程序,现在在调用ConnectAsync函数时,反序列化对象函数第24行出现异常。据我所知,通过在某个时刻对函数TLContext.getType(构造函数)进行调试,传递了值-1704251862。这是TLConfig对象的旧构造函数值,我完全无法理解应用程序从何处获得它。在TLSharp库的源中,此值不存在。我重新创建了session.dat文件,但没有帮助。请帮帮我,因为我现在的项目有大麻烦了。这是我的代码: using System;

我使用最新版本的TLSharp编译了我的控制台测试应用程序,现在在调用ConnectAsync函数时,反序列化对象函数第24行出现异常。据我所知,通过在某个时刻对函数TLContext.getType(构造函数)进行调试,传递了值-1704251862。这是TLConfig对象的旧构造函数值,我完全无法理解应用程序从何处获得它。在TLSharp库的源中,此值不存在。我重新创建了session.dat文件,但没有帮助。请帮帮我,因为我现在的项目有大麻烦了。这是我的代码:

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());
    }
使用系统;
使用系统图;
使用System.IO;
使用System.Linq;
Net系统;
使用System.Threading.Tasks;
使用Newtonsoft.Json;
使用TeleSharp.TL;
使用TeleSharp.TL.Messages;
使用TLSharp.Core;
名称空间测试
{
公营摄影测试器
{
FileSessionStore_sessionStore=新建FileSessionStore();
静态字符串寄存器电话=“+7985XXXXXXX”;
静态int-apid=XXXXX;
静态字符串apiHash=“49d60ed8bd78533986e05e3ffb60b443”;
静态字符串代码=“XXXXX”;
电报客户端;
类断言
{
静态内部void为NotNull(对象obj)
{
isnotnullhandler(obj);
}
静态内部空隙率(布尔条件)
{
IsTrueHandler(cond);
}
}
内部静态作用不为空;
内部静态作用不稳定;
受保护的void Init(Action notNullHandler、Action trueHandler)
{
isNotNullHandler=notNullHandler;
IsTrueHandler=trueHandler;
//在app.config中设置API设置和电话号码
//GatherTestConfiguration();
}
公共摄影测试器()
{
client=CreateClient();
InitializeAndAuthenticateClient(客户端,0.Wait();
}
公共客户端CreateClient()
{
客户机clt=空;
//clt=新电报客户端(APID、apiHash、会话存储,“C:\\Users\\hermann\\Documents\\session.dat”);
clt=新客户端(APID、apiHash);
返回clt;
}
公共异步任务初始化AndAuthenticateClient(电报客户端,int模式=1)
{
等待client.ConnectAsync();
var hash=await client.SendCodeRequestAsync(registeredPhone);
if(String.IsNullOrWhiteSpace(代码))
{
抛出新异常(“CodeToAuthenticate在app.config文件中为空,用您刚刚通过SMS/电报获得的代码填充它”);
}
TLUser=null;
尝试
{
user=wait client.MakeAuthAsync(registeredPhone、哈希、代码);
}
catch(CloudPasswordNeededException ex)
{
var password=wait client.GetPasswordSetting();
var password_str=“PasswordToAuthenticate”;
user=wait client.MakeAuthWithPasswordAsync(密码,password\u str);
}
捕获(无效的HoneCodeException ex)
{
抛出新异常(“app.config文件中的CodeToAuthenticate错误,请用您刚刚通过SMS/Telegram获得的代码填充它”,
ex);
}
Assert.IsNotNull(用户);
Assert.IsTrue(client.IsUserAuthorized());
}
这是一个异常:“构造函数无效或未调用Context.Init!”。 UPD
我想补充一点,这个问题是在将TLSharp升级到66级后出现的。

尝试使用FakeSessionStore而不是FileSessionStore。也许您的程序从文件中获取值。

我删除了“session.dat”从输出文件夹中,它修复了该问题。

如果您发布错误消息和调用代码,将有所帮助。我添加了我的代码和异常描述