6

I have the following method:

ApiResponse<T> PostMultipart<T>(string uploadUrl, NameValueCollection formParamters, params UploadFile[] uploadFiles);

UploadFile is just a Poco:

public class UploadFile
{
    public string FilePath { get; set; }
    public string ContentType { get; set; }
    public string ParameterName { get; set; }
}

By calling that method, everyhing works fine on the simulator with "Debug|iPhoneSimulator" and on my iPod Touch with iOS 5.1.1 with "Release|iPhone".

But when I am starting to debug the app on the device ("Debug|iPhone"), I get the following exception:

System.ExecutionEngineException: Attempting to JIT compile method 'Xyz.Api.ApiClient:PostMultipart (string,System.Collections.Specialized.NameValueCollection,Xyz.Api.UploadFile[])' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information.

I can't see any relevant information on the linked page. And I can't really understand why that behaviour only occurs when debugging on the phone.

Is someone else able to understand what is going on here? :)

asp_net
  • 3,567
  • 3
  • 31
  • 58

1 Answers1

6

Your code sample is not complete enough (to duplicate) but this is most likely because your <T> is a value-type (e.g. int, enum...).

The AOT compiler has difficulties generating code for value-types where code cannot be shared (like it can for any reference type). Workaround includes:

  • hinting the AOT compiler of what you need (ensuring <T> is known and code is generated for the value types you're using);

  • using a reference type (e.g. a string) instead of a value type (e.g. an int)

And I can't really understand why that behaviour only occurs when debugging on the phone.

iOS devices do not allow JITting code (Apple's restriction) so AOT is used. The iOS simulator does not have this restriction, so the JIT is used (because it's a lot faster than AOTing code).

poupou
  • 43,413
  • 6
  • 77
  • 174
  • Thanks, poupou, I will check that. The strange thing is, it seems only to occur in debug mode on the phone, not in release mode (it should be using AOT in both cases!?). – asp_net Oct 12 '12 at 10:28
  • Yes, AOT is used in both cases (debug and release modes). The compiled code *could* be different (e.g. with `#if DEBUG`) so maybe the hints are not getting thru in every case ? OTOH it could be a bug too. Could you create a small test case and attach it to a bug report on http://bugzilla.xamarin.com – poupou Oct 12 '12 at 12:41
  • 1
    poupou, could you please explain how to do this hinting? I have a case where code for all of the value types are absolutely necessary. – Patrick Hogan Jul 23 '13 at 14:14
  • I think by 'Hinting' he means something like: `var x = new Foo()` which can force the generation of `Foo`. – Ian Mercer Aug 21 '13 at 05:58