C# 为什么我在尝试使用AddonSuccessListener时遇到InvalidCastException?

C# 为什么我在尝试使用AddonSuccessListener时遇到InvalidCastException?,c#,android,firebase,xamarin,C#,Android,Firebase,Xamarin,所以我目前正在做一个Xamarin项目和我的App.Android项目,我在尝试连接Firebase Firestore时遇到了困难 公共类FirestoreService:IFirestore、OnSuccessListener { JavaDictionary hash=newjavadictionary{{“test”,2}; public IntPtr Handle=>抛出新的NotImplementedException(); IntPtr IJavaObject.Handle=>抛出

所以我目前正在做一个Xamarin项目和我的App.Android项目,我在尝试连接Firebase Firestore时遇到了困难

公共类FirestoreService:IFirestore、OnSuccessListener
{
JavaDictionary hash=newjavadictionary{{“test”,2};
public IntPtr Handle=>抛出新的NotImplementedException();
IntPtr IJavaObject.Handle=>抛出新的NotImplementedException();
公共异步任务PutTest(字符串UID)
{
尝试
{
DocumentReference docRef=FirebaseFirestore.Instance
.收款(“DB”)
.文件(UID);
等待docRef.Set(散列);
返回“成功!”;
}
捕获(System.e例外)
{
返回e.ToString();
}
}
公共异步任务RtvAllF(字符串UID)
{
尝试
{
CollectionReference docRef=FirebaseFirestore.Instance
.收款(“DB”)
.文件(UID)
.收款(“Fach”);
等待docRef.Get().AddOnSuccessListener(此);
返回“成功!”;
}
catch(System.Exception e){抛出新异常(e.ToString());}
}
void IDisposable.Dispose(){抛出新的NotImplementedException();}
void IOnSuccessListener.OnSuccess(Java.Lang.Object结果)
{
var snap=(QuerySnapshot)结果;
如果(!snap.IsEmpty)
{
var docs=snap.Documents;
foreach(单据快照项目在单据中)
{
调试写入线(项目);
}
}
}
}
调试:

12-27 15:23:23.247 W/me.MyAp(14029): Accessing hidden field Ljava/nio/Buffer;->address:J (light greylist, reflection)
12-27 15:23:23.397 W/me.MyAp(14029): Accessing hidden field Ljava/net/Socket;->impl:Ljava/net/SocketImpl; (light greylist, reflection)
12-27 15:23:23.398 W/me.MyAp(14029): Accessing hidden method Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard; (light greylist, linking)
12-27 15:23:23.402 W/me.MyAp(14029): Accessing hidden method Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V (light greylist, linking)
12-27 15:23:23.402 W/me.MyAp(14029): Accessing hidden method Ljava/net/InetAddress;->isNumeric(Ljava/lang/String;)Z (light greylist, reflection)
12-27 15:23:23.403 W/me.MyAp(14029): Accessing hidden field Ljava/io/FileDescriptor;->descriptor:I (light greylist, JNI)
12-27 15:23:23.461 W/me.MyAp(14029): Accessing hidden method Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V (light greylist, reflection)
12-27 15:23:23.498 W/me.MyAp(14029): Accessing hidden method Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy; (light greylist, linking)
12-27 15:23:23.498 W/me.MyAp(14029): Accessing hidden method Ldalvik/system/BlockGuard$Policy;->onNetwork()V (light greylist, linking)
**System.Exception:** 'System.InvalidCastException: Specified cast is not valid.
  at Android.Gms.Tasks.TaskInvoker.AddOnSuccessListener (Android.Gms.Tasks.IOnSuccessListener p0) [0x0000c] in <b4d5e1ae9bbc49e2b688cfc4a2ef5009>:0 
  at MyApp.FirestoreService.RtvAllF (System.String UID) [0x00042] in C:\Users\%USER%\Source\Repos\%REPOS%\MyApp\MyApp\MyApp.Android\Code\FirestoreService.cs:57 '

12-27 15:23:33.298 W/Firestore(14029): (0.6.6-dev) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds
12-27 15:23:33.298 W/Firestore(14029): 
12-27 15:23:33.298 W/Firestore(14029): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

12-27 15:23:23.247 W/me.MyAp(14029):访问隐藏字段Ljava/nio/Buffer;->地址:J(浅灰色列表,反射)
12-27 15:23:23.397 W/me.MyAp(14029):访问隐藏字段Ljava/net/Socket;->impl:Ljava/net/SocketImpl;(浅灰色列表,反射)
12-27 15:23:23.398 W/me.MyAp(14029):访问隐藏方法Ldalvik/system/CloseGuard;->get()Ldalvik/system/CloseGuard;(浅灰色列表,链接)
12-27 15:23:23.402 W/me.MyAp(14029):访问隐藏方法Ldalvik/system/CloseGuard;->open(Ljava/lang/String;)V(浅灰色列表,链接)
12-27 15:23:23.402 W/me.MyAp(14029):访问隐藏方法Ljava/net/InetAddress;->isNumeric(Ljava/lang/String;)Z(浅灰色列表,反射)
12-27 15:23:23.403 W/me.MyAp(14029):访问隐藏字段Ljava/io/FileDescriptor;->描述符:I(浅灰色列表,JNI)
12-27 15:23:23.461 W/me.MyAp(14029):访问隐藏方法Ljava/security/spec/ECParameterSpec;->setCurveName(Ljava/lang/String;)V(浅灰色列表,反射)
12-27 15:23:23.498 W/me.MyAp(14029):访问隐藏方法Ldalvik/system/BlockGuard;->getThreadPolicy()Ldalvik/system/BlockGuard$Policy;(浅灰色列表,链接)
12-27 15:23:23.498 W/me.MyAp(14029):访问隐藏方法Ldalvik/system/BlockGuard$Policy;->onNetwork()V(浅灰色列表,链接)
**System.Exception:*'System.InvalidCastException:指定的强制转换无效。
在Android.Gms.Tasks.TaskInvoker.AddOnSuccessListener(Android.Gms.Tasks.IOnSuccessListener p0)[0x0000c]中:0
在C:\Users\%USER%\Source\Repos\%Repos%\MyApp\MyApp\MyApp\MyApp.Android\Code\FirestoreService.cs:57中的MyApp.FirestoreService.RtvAllF(System.String UID)[0x00042]
12-27 15:23:33.298 W/Firestore(14029):(0.6.6-dev)[OnlineStateTracker]:无法访问云Firestore后端。后端在10秒内没有响应
12-27 15:23:33.298 W/消防仓库(14029):
12-27 15:23:33.298 W/Firestore(14029):这通常表示您的设备目前没有健康的Internet连接。客户端将在脱机模式下运行,直到能够成功连接到后端。
我确信连接工作正常,因为我试图从另一个空区写入DB。但我无法检索数据。Firestore的安全规则是在测试模式下设置的。也不应该有任何问题。
所有NuGet软件包都以最新版本运行。
添加断点时,系统会在AddOnSuccessListener处捕获异常:

System.Exception:*'System.InvalidCastException:指定的强制转换无效。 在Android.Gms.Tasks.TaskInvoker.AddOnSuccessListener(Android.Gms.Tasks.IOnSuccessListener p0)[0x0000c]中:0 在C:\Users\joshu\Source\Repos\%USER%\MyApp\MyApp\MyApp\MyApp.Android\Code\FirestoreService.cs中的MyApp.FirestoreService.RtvAllF(System.String UID)[0x00042]中


是否继承自正确的基类?您的类定义在此处是关键的,请粘贴整个类