HttpClient执行运行时错误:ExecutionEngineException - 尝试使用--aot-only进行JIT编译方法

时间:2013-09-07 03:19:26

标签: ios xamarin.ios httpclient xamarin

我正在使用安装了iOS 6.4.4更新的Xamarin(MAC)。我的触摸项目使用启用了HttpClient的PCL库。每次我执行使用HttpClient的方法时,我都会遇到以下运行时错误:

System.ExecutionEngineException: Attempting to JIT compile method '(wrapper delegate-invoke) <Module>:invoke_void__this___HttpWebRequest_long (System.Net.HttpWebRequest,long)' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

  at System.Lightup.Call[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String methodName, Int64 parameter) [0x00000] in <filename unknown>:0 
  at System.Lightup.Set[HttpWebRequest,Int64] (System.Delegate& storage, System.Net.HttpWebRequest instance, System.String propertyName, Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.HttpWebRequestLightup.SetContentLength (System.Net.HttpWebRequest instance, Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpWebRequest.set_ContentLength (Int64 value) [0x00000] in <filename unknown>:0 
  at System.Net.Http.HttpClientHandler.StartRequest (System.Object obj) [0x00000] in <filename unknown>:0

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

我知道我差不多3年了:)但今天我遇到了这个问题。现在支持PCL,所以我认为在这个问题上添加一些额外的信息可能会有所帮助。

如果您在PCL项目中引用System.Net.Http,例如使用Microsoft.Net.Http NuGet包,则必须将该引用添加到您的iOS项目中。您只需在iOS项目中安装此NuGet包即可。

这将迫使iOS项目使用Mono iOS版本的System.Net.Http dll,而不是PCL的变种,这可能是net45或类似的东西。

我认为发生此问题是因为System.Net.Http的net45变体使用反射来调用某些方法。请注意,错误表明尝试了一些调用,并且这需要JIT编译。但是,这在iOS物理设备上禁止,而在iOS模拟器上禁止。 iOS物理设备需要Ahead of Time(aot)编译。

Attempting to JIT compile method '(wrapper delegate-invoke) <Module>:invoke_callvirt_void_HttpWebRequest_bool (System.Net.HttpWebRequest,bool)'

答案 1 :(得分:0)

PCL仍然不受官方支持。特别是涉及async / await时。在此期间,您可以为什么这样做并创建一个特定于平台的类库并将源文件添加为链接(如果您将文件从Windows资源管理器拖放到VS解决方案资源管理器,则Visual Studio会执行此操作,而Xamarin Studio会自动提供链接选项当它看到目标项目之外的源文件时。)