Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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#云firestore检索数组_C#_Firebase_Visual Studio_Google Cloud Firestore - Fatal编程技术网

C#云firestore检索数组

C#云firestore检索数组,c#,firebase,visual-studio,google-cloud-firestore,C#,Firebase,Visual Studio,Google Cloud Firestore,我想检索cpu_ID数组,但它会抛出 System.InvalidCastException:'System.Collections.Generic.List'1[System.Object]'System.Array'。 我的代码 public static async Task RetriveDataFromFirestore(string email, string digitalkey) { Query collecti

我想检索cpu_ID数组,但它会抛出

System.InvalidCastException:'System.Collections.Generic.List'1[System.Object]'System.Array'。

我的代码

    public static async Task RetriveDataFromFirestore(string email, string digitalkey)
    {    

       
            Query collection = Database.Collection("customers").Document(UserId).Collection("subscriptions");
            QuerySnapshot subscriptions = await collection.GetSnapshotAsync();

            foreach(DocumentSnapshot use in subscriptions)
            {
                DocumentReference docref = Database.Collection("customers").Document(UserId).Collection("subscriptions").Document(use.Id.ToString());
                DocumentSnapshot snap = await docref.GetSnapshotAsync();

                
                if (snap.Exists)
                {
                    Dictionary<string, object> key = snap.ToDictionary();
                    
                    foreach (var item in key)
                    {
                        //Console.WriteLine(item);
                        if (item.Key == "cpu_ids")
                        {
                            foreach (var stoixeio in (Array)item.Value)
                            {
                                Console.WriteLine(stoixeio);
                            }
                        }
                    }
                }
            }
        
    }
公共静态异步任务从FireStore检索数据(字符串电子邮件、字符串数字键)
{    
查询集合=数据库。集合(“客户”)。文档(用户ID)。集合(“订阅”);
QuerySnapshot subscriptions=wait collection.GetSnapshotAsync();
foreach(订阅中使用的文档快照)
{
DocumentReference docref=Database.Collection(“customers”).Document(UserId).Collection(“subscriptions”).Document(use.Id.ToString());
DocumentSnapshot snap=await docref.GetSnapshotAsync();
if(snap.Exists)
{
Dictionary key=snap.ToDictionary();
foreach(键中的var项)
{
//控制台写入线(项目);
如果(item.Key==“cpu\U ID”)
{
foreach(数组中的var stoixeio item.Value)
{
控制台写入线(stoixeio);
}
}
}
}
}
}
这就是问题所在:

foreach(数组中的var stoixeio item.Value)

您正在将
item.Value
强制转换为数组,但它不是数组。这是一张单子。根据,Firestore阵列的默认类型为
列表
。因此,只需转换为
列表
,而不是
数组
(或者甚至只转换为非泛型的
IEnumerable
类型),就可以了。

请发布完整的堆栈跟踪,理想情况下是一个?(所有这些问号的例外看起来有点奇怪……这些想法来自何方?)我怀疑这是否真的与Visual Studio有关,因此我建议删除该标记。