简体   繁体   中英

HttpClient execution runtime error: ExecutionEngineException - Attempting to JIT compile method with --aot-only

I'm using Xamarin (MAC) with iOS 6.4.4 update installed. My touch project uses PCL library with HttpClient enabled. Every time I execute method which uses HttpClient I'm getting the following runtime error:

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

How can I fix that issue?

I know I'm almost 3 years late :) but today I ran into this issue. PCL's are now supported so I thought it might be helpful to add some additional information to this question.

If you reference System.Net.Http in your PCL project, by for instance using the Microsoft.Net.Http NuGet package, you then have to add that reference also to your iOS project. You can simply do this by also installing this NuGet package on your iOS project.

This will force the iOS project to use the Mono iOS version of the System.Net.Http dll's instead of the PCL's variant, which is probably net45 or something like that.

I think that this problem occurs because the net45 variant of System.Net.Http uses reflection to invoke some methods. Note that the error states that some invocation is tried and that this requires a JIT compilation. This is however prohibited on iOS physical devices and not on iOS simulators. iOS physical devices require Ahead of Time(aot) compiling.

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

PCLs are still not offically supported. Especially when async/await is involved. In the meantime you could to why I do and create a platform specific class library and adding your source files as Link (Visual Studio does that if you ALT-Drag files from Windows Explorer to the VS Solution Explorer and Xamarin Studio offers the Link option automatically when it sees source files outside of the target project).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM