Firesharp:执行请求时出错。路径:0/,方法:PUT

Firesharp: An error occured while execute request. Path : 0/ , Method : PUT

我正在使用 C# 探索 Firebase 实时数据库 (RTDB),并在 .NET 控制台应用程序上试用 Firesharp 框架。我已按照大多数在线入门教程进行操作,但无法 post 向我的 RTDB 发送任何数据。我在 AddData().Wait():

处抛出此错误

System.AggregateException has been thrown

"One or more errors occurred. (An error occured while execute request. Path : 0/ , Method : PUT)"

我的实现是这样的:

class Program
{
    static IFirebaseConfig config = new FirebaseConfig
    {
        AuthSecret="MY_AUTH_SECRET",
        BasePath="https://MY_APP.firebaseio.com/"
    };

    static IFirebaseClient client;

    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        client = new FireSharp.FirebaseClient(config);

        if (client != null)
        {
            Console.WriteLine("Connection established!");
            AddData().Wait(); //Crashed here with above error
        }
    }

    public static async Task AddData() 
    {
        var data = new Data
        {
            id = "Hello",
            text = "World"
        };

        SetResponse response = await client.SetAsync("0/", data);
        Data result = response.ResultAs<Data>();
    }
}

我是 C# 的新手。我哪里做错了?

我在 Mac 上使用 VS,因此没有编写表单应用程序来进行测试。

编辑

完整错误日志:

System.AggregateException: "One or more errors occurred. (An error occured while execute request. Path : 0 , Method : PUT)" ---> System.Exception {FireSharp.Exceptions.FirebaseException}: "An error occured while execute request. Path : 0 , Method : PUT" ---> System.Exception {System.IO.FileNotFoundException}: "Could not load file or assembly 'System.Security.Permissions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.\n"

at at Newtonsoft.Json.Serialization.JsonTypeReflector.get_DynamicCodeGeneration()\n at Newtonsoft.Json.Serialization.JsonTypeReflector.get_ReflectionDelegateFactory()\n at Newtonsoft.Json.Serialization.DefaultContractResolver.GetDefaultCreator(Type createdType)\n at Newtonsoft.Json.Serialization.DefaultContractResolver.InitializeContract(JsonContract contract)\n at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateObjectContract(Type objectType)\n at Newtonsoft.Json.Serialization.DefaultContractResolver.CreateContract(Type objectType)\n at Newtonsoft.Json.Serialization.DefaultContractResolver.ResolveContract(Type type)\n at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)\n at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)\n at Newtonsoft.Json.JsonConvert.SerializeObjectInternal(Object value, Type type, JsonSerializer jsonSerializer)\n at FireSharp.RequestManager.PrepareRequest(HttpMethod method, Uri uri, Object payload)\n at FireSharp.RequestManager.RequestAsync(HttpMethod method, String path, QueryBuilder queryBuilder, Object payload)

--- End of inner exception stack trace --- at FireSharp.RequestManager.RequestAsync(HttpMethod method, String path, QueryBuilder queryBuilder, Object payload)\n at FireSharp.FirebaseClient.SetAsync[T](String path, T data)\n at FiresharpTest.Program.AddData() in /Users/MYNAME/Desktop/C#Projects/FiresharpTest/FiresharpTest/Program.cs:40

--- End of inner exception stack trace --- at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\n at System.Threading.Tasks.Task.Wait()\n at FiresharpTest.Program.Main(String[] args) in /Users/MYNAME/Desktop/C#Projects/FiresharpTest/FiresharpTest/Program.cs:28

好的,所以这个问题的问题是我安装了两个 Nuget 包,FiresharpFiresharp.Serialization.JsonNet

我删除了 Firesharp,然后修改了我的 AddData() 函数,一切正常。

public static async Task AddData() 
{
    var data = new Data
    {
        id = "Hello",
        text = "World"
    };

    SetResponse response = await client.SetTaskAsync("0", data); //Change to SetTaskAsync here
    Data result = response.ResultAs<Data>();
}