1

我是初学者,最近尝试开始使用 FireSharp,甚至传输了一些数据:

这是我向服务器发送数据的第一个代码:

public static class Client
{
   static IFirebaseClient client;

   static IFirebaseConfig config = new FirebaseConfig
   {
       AuthSecret = "MyAuthSecret",
       BasePath = "MyBasePath"
   };


   public static bool Start()
   {
       client = new FirebaseClient(config);

       if (client != null) 
       {
           return true; 
       } else {
           return false;
       }
   }

   public static void Send(Data data)
   {
       SetResponse response = await client.SetAsync("Testpath", data);
   }

但是在该行SetResponse response = await client.SetAsync("Testpath", data);,我收到以下错误消息:
The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.

我仍然能够发送数据,只需将线路减少到client.SetAsync("Testpath", data);. 我知道这并不理想,因为我没有以那种方式得到回应,但它奏效了!

真正的问题是,我没有设法为FirebaseResponse response = await client.GetAsync("Testpath");. 这样我目前无法从服务器获取数据。

有谁知道问题可能是什么或如何解决?

我的想法是:

  • 也许这与我将所有这些都放在一个静态类中的事实有关。
  • 也许 FireSharp 库在当前版本中已损坏。
  • 也许我可以手动将这些方法标记为异步,因为这就是错误消息所说的。
  • 或者我可以手动更改它的返回类型,如错误消息所述。
  • "await"也许我理解"async"错了。
  • 手册说,"FirebaseClient uses Newtonsoft.Json by default.也许这与它有关。

但是我没有尝试过任何一个,因为我不知道如何。我不知道是否可以更改库的代码,或者任何错误消息的含义"change the return type"。我看了一个教程并查看了手册,但找不到有关此问题的任何信息。

我非常感谢任何帮助,因为到目前为止我无法在 Internet 上找到有关此问题的任何信息。

4

1 回答 1

2

您的发送方法必须是async

public static async Task Send(Data data)

于 2020-05-10T18:30:30.597 回答