Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
Mono organizations on
GitHub to continue tracking issues. Bugzilla will remain
available for reference in read-only mode. We will continue to work
on open Bugzilla bugs, copy them to the new locations
as needed for follow-up, and add the new items under Related
Our sincere thanks to everyone who has contributed on this bug
tracker over the years. Thanks also for your understanding as we
make these adjustments and improvements for the future.
Please create a new report on
Developer Community or GitHub with
your current version information, steps to reproduce, and relevant error
messages or log files if you are hitting an issue that looks similar to
this resolved bug and you do not yet see a matching new report.
Created attachment 2593 [details]
Sample project. Please run on device. Press Unpack button 4-5 times to see issue.
I am using a native static library and the function it is warning is using JIT works about 80% of the time, then suddenly, the same call that worked previously fails with that error.
The actual library is the 'minizip' subset of zlib that I compiled for iOS (AMRv6 + AMRv7 combined static lib)
It uses both managed-to-native "[DllImport ("__Internal", CallingConvention=CallingConvention.Cdecl)]" calls and native-to-managed calls (which I wrapped in [MonoPInvokeCallback (typeof (TestErrorFileFunc))])
The weirdest part is that the error is "System.ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-native) zipsharp.OpenFileFunc:wrapper_aot_native (intptr&,intptr,string,int)' while running with --aot-only.", but when I put console logging within the managed delegate it complains about, the console outputs before the error happens.
I made a sample project to easily reproduce the issue. Please run that on an actual iPhone and press the "Unpack" button multiple times. In my case, I start seeing JIT error around the 5th press of the button.
I can reproduce the issue, but I couldn't find out what's going on.
Zoltan, can you have a look?
You have to mark the delegates used to wrap native functions, i.e. OpenFileFunc with the
MonoNativeFunctionWrapper attribute, so the AOT compiler knows about them:
internal delegate IntPtr OpenFileFunc (IntPtr opaque, string filename, int mode);
Added a more useful error message to the ExecutionEngineException in this case.
There is still a mono problem here, [MonoNativeFunctionWrapper] and [UnmanagedFunctionPointerAttribute] cannot be specified at the same time. For now, remove the
[UnmanagedFunctionPointerAttribute], its not needed on ios.
This call seems to be Monotouch specific and does not work with Mono for Android. This is slightly problematic as I assume native libraries would probably be called by libraries to be used on multiple platforms.
Can't the [MonoNativeFunctionWrapper] be automatically implied when using [UnmanagedFunctionPointerAttribute]?
Implemented that suggestion.