C# MonoTouch&;由于对象的当前状态,LINQ-操作无效

C# MonoTouch&;由于对象的当前状态,LINQ-操作无效,c#,wcf,linq,exception,xamarin.ios,C#,Wcf,Linq,Exception,Xamarin.ios,我有一个应用程序,它使用Mac上的Monotouch/C#作为前端,在后端从VS2010中的WCF服务中提取数据。在我离开之前,昨晚一切都像梦一样顺利,而今天,我不知道发生了什么。我所能看到的是,这是来自Monotouch的linq的一个例外,看起来我做的一切都很好,因为我在过去几天里没有接触过这段代码 在我从WCF获得一个GetAllStaffResult对象之后,我回到主线程,然后调用这个方法Populate(): 以下是堆栈跟踪: System.InvalidOperationExcept

我有一个应用程序,它使用Mac上的Monotouch/C#作为前端,在后端从VS2010中的WCF服务中提取数据。在我离开之前,昨晚一切都像梦一样顺利,而今天,我不知道发生了什么。我所能看到的是,这是来自Monotouch的linq的一个例外,看起来我做的一切都很好,因为我在过去几天里没有接触过这段代码

在我从WCF获得一个
GetAllStaffResult
对象之后,我回到主线程,然后调用这个方法
Populate()

以下是堆栈跟踪:

System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Linq.Enumerable.First[FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate, Fallback fallback) [0x0004a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:816
at System.Linq.Enumerbale.First [FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:843
at ADMobileServices.BOTransferDTOs.GetAllStaffResult.Populate() [0x0003b] (my code)
不确定是什么原因造成的。。。有人有什么想法吗?去看看我是否能找到MT源文件,这样我就能看到那些行了

哦,
这个
是一个
GetAllStaffResult
,上面的方法是一个分部类,它包含一组工作人员、特许经营权和地点。populate方法会根据员工的特许经营ID来填充每个员工的特许经营名称。我这样做是因为我会返回500名具有长期特许经营名称的员工,并且我通过自己在客户端重建对象图来节省带宽

因为数据库中存在外键关系,所以我100%确定Single将始终返回结果。First()也给了我同样的问题


编辑:堆栈跟踪是针对我在Single()方法之后尝试的第一个()方法。我现在正在检查源代码,将报告我的发现。

如果序列为空,就会发生这种情况。

你说得对。似乎我排除了一个测试特许经营实体,我忘了将他们从员工名单中排除。谢谢
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at System.Linq.Enumerable.First[FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate, Fallback fallback) [0x0004a] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:816
at System.Linq.Enumerbale.First [FranchiseListingItem] (IEnumerable'1 source, System.Func2 predicate) [0x00007] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:843
at ADMobileServices.BOTransferDTOs.GetAllStaffResult.Populate() [0x0003b] (my code)