1

这是我的代码

public int GetUsersSqlCount()
{
    // Here i get the Error
    return this.GetUsersSql().Count();
}

public IEnumerable<CsUser> GetUsersSql()
{       
    return (from x in this._storage.CsUsers
           join y in this._storage.CeMitarbs on x.MitNr equals y.MitNr
           select x).OrderBy(x => x.KurzZch);
}

我收到以下错误:

Unhandled Exception: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<ToLookup`2>m__5A<Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb, System.Nullable`1<int>> (Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb)' while running with --aot-only.

  at System.Linq.Enumerable.ToLookup[CeMitarb,Nullable`1,CeMitarb] (IEnumerable`1 source, System.Func`2 keySelector, System.Func`2 elementSelector, IEqualityComparer`1 comparer) [0x00079] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2966 
  at System.Linq.Enumerable.ToLookup[CeMitarb,Nullable`1] (IEnumerable`1 source, System.Func`2 keySelector, IEqualityComparer`1 comparer) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2934 
  at System.Linq.Enumerable+<CreateJoinIterator>c__Iterator18`4[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser,Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb,System.Nullable`1[System.Int32],Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].MoveNext () [0x00023] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:1157 
  at System.Collections.Generic.List`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0 
  at System.Collections.Generic.List`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser]..ctor (IEnumerable`1 collection) [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.ToArray[CsUser] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 
  at System.Linq.QuickSort`1[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser]..ctor (IEnumerable`1 source, System.Linq.SortContext`1 context) [0x00000] in <filename unknown>:0 
  at System.Linq.QuickSort`1+<Sort>c__Iterator2F[Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CsUser].MoveNext () [0x00000] in <filename unknown>:0 
  at System.Linq.Enumerable.Count[CsUser] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 
  at CSMobile.Logic.Forms.Login_Dal.GetUsersSqlCount () [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Dal.cs:38 
  at CSMobile.Logic.Forms.Login_Logic.GetUsers () [0x0001f] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:198 
  at CSMobile.Logic.Forms.Login_Logic.Anmelden2 (Int32 selectedProduct) [0x00050] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:416 
  at CSMobile.UI.Login.Logic_LoginStepCompleted (Login_StepResult result) [0x0003e] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:325 
  at CSMobile.Logic.Forms.Login_Logic.Anmelden1 () [0x00084] in /Volumes/Mobile2011/Mobile 2011/trunk/WinCE/CSMobile/CSMobile.Logic/Forms/Login.Logic.cs:364 
  at CSMobile.UI.Login.StartLogin () [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:75 
  at CSMobile.UI.Login.Pad_Start_TouchUpInside (MonoTouch.Foundation.NSObject sender) [0x00000] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Forms/Login.cs:235 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args) [0x00000] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:34 
  at CSMobile.UI.Application.Main (System.String[] args) [0x0000a] in /Volumes/Mobile2011/Mobile 2011/trunk/IOS/CSMobile/CSMobile.UI/Main.cs:18 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ExecutionEngineException: Attempting to JIT compile method 'System.Linq.Enumerable:<ToLookup`2>m__5A<Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb, System.Nullable`1<int>> (Genesis.DataAccess.Schema.Mobile.V1.Wrapper.CeMitarb)' while running with --aot-only.
4

4 回答 4

1

我认为这里的限制实际上是由于通用虚拟方法 - http://docs.xamarin.com/ios/about/limitations#Generic_Virtual_Methods

邮件列表上有一个非常相似的问题的讨论:

听起来那个线程没有找到解决方案

可能值得直接联系 Xamarin 支持。http://bugzilla.xamarin.com/

于 2012-06-14T17:26:21.963 回答
0

由于 AOT 编译,MonoTouch 上的泛型有点奇怪。iOS 不允许真正的运行时/JIT,因此它必须提前编译所有内容。

在这种特殊情况下,您返回的方法IEnumerable<CsUser>很可能是罪魁祸首。通用接口会导致问题。尝试将您的返回类型更改为一个List<CsUser>或任何其他实现的具体类IEnumerable<CsUser>

于 2012-06-14T14:30:14.843 回答
0

目前我不知道 Xamarin 的便捷解决方案。然而,Unity 3D 有这样的解决方案。

您可以尝试LINQ to iOS。它是 LINQ to Objects 扩展方法的自定义实现,可在 iOS 上运行而不会出现 JIT 编译错误。如果您使用的是 Xamarin,您可以尝试将 .dll 从 LINQ 获取到 iOS 并在您的项目中使用它。毕竟,Xamarin 和 Unity 都使用 Mono 编译器。

于 2014-10-15T10:52:31.677 回答
0

已知 OrderBy 在这种情况下会失败。这似乎已在 MonoTouch 2.10 版中得到修复,但不幸的是,如果您使用的是 Unity 之类的引擎,那么目前仅附带 2.6(截至 4.3.x)。

https://bugzilla.xamarin.com/show_bug.cgi?id=2155#c11

于 2013-10-24T23:43:51.600 回答