C# Tdlib JSON接口';双自由';错误Linux
我试图弄清楚Telegram Library JSON接口在C#上的一个小学习项目中是如何工作的 我的代码如下:C# Tdlib JSON接口';双自由';错误Linux,c#,json,pinvoke,dllimport,tdlib,C#,Json,Pinvoke,Dllimport,Tdlib,我试图弄清楚Telegram Library JSON接口在C#上的一个小学习项目中是如何工作的 我的代码如下: using System; using System.Runtime.InteropServices; using Newtonsoft.Json.Linq; namespace TDLibWork { class Program { // API DETAILS static string api_id = "BLAH&q
using System;
using System.Runtime.InteropServices;
using Newtonsoft.Json.Linq;
namespace TDLibWork
{
class Program
{
// API DETAILS
static string api_id = "BLAH";
static string api_hash = "BLAHBLAHBLAHBLAHBLAH";
// NATIVE DLL INTERFACES
[DllImport("tdjson")] private static extern IntPtr td_json_client_create ();
[DllImport("tdjson")] private static extern void td_json_client_send (IntPtr client, string request);
[DllImport("tdjson")] private static extern string td_json_client_recieve (IntPtr client, double timeout);
[DllImport("tdjson")] private static extern string td_json_client_execute (IntPtr client, string request);
[DllImport("tdjson")] private static extern void td_json_client_destroy (IntPtr client);
[DllImport("tdjson")] private static extern int td_create_client_id ();
[DllImport("tdjson")] private static extern void td_send (int client_id, string request);
[DllImport("tdjson")] private static extern string td_receive (double timeout);
[DllImport("tdjson")] private static extern string td_execute (string request);
static void Main(string[] args)
{
// GET AN INSTANCE OF THE TDJSON API
int client_id = td_create_client_id();
// Console.WriteLine(td_execute("{\"@type\": \"getTextEntities\", \"text\": \"@telegram /test_command https://telegram.org telegram.me\", \"@extra\": [\"5\", 7.0, \"ä\"]}"));
td_send(client_id, "{\"@type\": \"getAuthorizationState\", \"@extra\": 1.01234}");
// MAIN PROGRAM LOOP
while (true) {
string json_data = td_receive(10.0);
if(!string.IsNullOrEmpty(json_data)) {
var response = JObject.Parse(json_data);
string type = (string) response["@type"];
Console.WriteLine(type);
}
}
}
}
}
我不知道C#在大多数情况下是如何工作的,但我已经在Python示例的基础上结合了这一点。C#示例使用了Linux上无法使用的特性,因此我必须使用P/Invoke来处理JSON接口。但是,接口仍然与<代码> For()一起崩溃:在TCACHE 2 中检测到了双自由度,这是我所知道的,是C++编译库本身的一个错误。
我只是需要一些帮助来理解我哪里出了问题,以及我能做些什么来修复它,因为在所有的例子中,都需要一个控制循环来读取来自TDLib的传入响应,但它似乎每次都会在几个请求之后崩溃
免责声明:我对C#的了解相当有限,因此我只以我对其他语言的了解作为基准,我不能说进展顺利…您可能在工作中犯了一些错误。您能否共享您试图调用的方法的文档(或至少是头文件)?另外,您能否将您的问题分享给我们,让我们对您得到的异常进行完整的追溯?这可能会提示您的编组哪里出了问题。您可以从这里借用定义(或完整的项目代码):@SimonMourier我尝试过使用它,但从外观上看,Linux不支持它,Linux无法像Windows一样与主TDLib库接口,文档说明了这一点,因此,在Linux上必须使用P/Invoke方法。@dbc这是我用于P/Invoke语句的引用:。至于回溯,我没有得到任何回溯,即使在调试模式下,dotnet也会为我吐出一行错误。这个项目也有linux p/invoke: