2

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?

2
  • Can you please post the code that tries to call this? Sep 9, 2013 at 14:36
  • var client = new HttpClient(); var content = await client.DownloadStringAsync("google.com"); this code is inside PCL library with 158 profile
    – Mando
    Sep 9, 2013 at 22:05

2 Answers 2

1

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)'
1
  • Thank you very much, this solved my problem! I had to install this package on my iOS project!
    – tf.alves
    Aug 22, 2016 at 14:36
0

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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.