Bug 56962 - Xamarin.iOS binding - Attempting to JIT compile method 'Class:.ctor ()' while running in aot-only mode.
Summary: Xamarin.iOS binding - Attempting to JIT compile method 'Class:.ctor ()' while...
Status: RESOLVED DUPLICATE of bug 53872
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: unspecified
Hardware: PC Mac OS
: --- normal
Target Milestone: 15.3
Assignee: Rolf Bjarne Kvinge [MSFT]
: 56271 ()
Depends on:
Reported: 2017-05-30 14:45 UTC by Flash3001
Modified: 2017-08-08 06:40 UTC (History)
12 users (show)

Is this bug a regression?: ---
Last known good build:

sample reproduction projects (8.11 KB, application/zip)
2017-05-30 14:45 UTC, Flash3001

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and 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 Links.

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.

Related Links:

Description Flash3001 2017-05-30 14:45:23 UTC
Created attachment 22551 [details]
sample reproduction projects

The following exception is thrown when running a simple iOS Binding on Device using Debug configuration. 

"Attempting to JIT compile method 'bindingjitbug.NormalClass:.ctor ()' while running in aot-only mode. See     https://developer.xamarin.com/guides/ios/advanced_topics/limitations/ for more information."

The same doesn't apply for Release or Simulator. 

The binding is as follows - it's not actually a binding because there's not underling Objective-C class. 

    interface NormalClass { }

The code where the exception happens is 

    var normal = new bindingjitbug.NormalClass();

If I subclass NormalClass as in

    class UnusedSubClass : bindingjitbug.NormalClass { }

The exception goes away

If the class is defined in a ordinary .cs (not ApiDefinition.cs) file inside the binding project it will just work.

    public class NormalClass { }

In the case for the bug (Debug + Device), the Mono Ahead of Time output says:

    Mono Ahead of Time compiler - compiling assembly /Users/flash/Desktop/Testes/bindingjitbug/bindingjitbug/jitapp/obj/iPhone/Debug/device-builds/iphone8.1-10.3.2/mtouch-cache/Build/bindingjitbug.dll
    AOTID 8B535E52-F486-C779-697E-03931E571400
    Code: 1172(48%) Info: 22(0%) Ex Info: 414(17%) Unwind Info: 71(2%) Class Info: 218(9%) PLT: 8(0%) GOT Info: 364(15%) Offsets: 150(6%) GOT: 328
    Compiled: 4/5 (80%), No GOT slots: 0 (0%), Direct calls: 0 (100%)
    Output file: '/Users/flash/Desktop/Testes/bindingjitbug/bindingjitbug/jitapp/obj/iPhone/Debug/device-builds/iphone8.1-10.3.2/mtouch-cache/arm64/bindingjitbug.dll.s'.
    Linking symbol: '_mono_aot_module_bindingjitbug_info'.
    JIT time: 14 ms, Generation time: 1 ms, Assembly+Link time: 1 ms.

For Release + Device it states:

    Mono Ahead of Time compiler - compiling assembly /Users/flash/Desktop/Testes/bindingjitbug/bindingjitbug/jitapp/obj/iPhone/Release/mtouch-cache/64/Build/bindingjitbug.dll
    AOTID 19A28098-5EF1-5B87-DD99-470596B498F4
    Code: 612(43%) Info: 23(1%) Ex Info: 15(1%) Unwind Info: 85(5%) Class Info: 170(11%) PLT: 10(0%) GOT Info: 376(26%) Offsets: 138(9%) GOT: 328
    Compiled: 5/5 (100%), No GOT slots: 0 (0%), Direct calls: 0 (0%)
    Output file: '/Users/flash/Desktop/Testes/bindingjitbug/bindingjitbug/jitapp/obj/iPhone/Release/mtouch-cache/arm64/bindingjitbug.dll.s'.
    Linking symbol: '_mono_aot_module_bindingjitbug_info'.
    JIT time: 11 ms, Generation time: 2 ms, Assembly+Link time: 0 ms.

My setup is:

Visual Studio Community 2017 for Mac
Version 7.0.1 (build 24)
Installation UUID: 459515c7-a0c3-4828-ab6a-39af3cd0ce78
	Mono (2017-02/5077205) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 500010001

Apple Developer Tools
Xcode 8.3.2 (12175)
Build 8E2002

Version: (Visual Studio Community)
Hash: d2270eec
Branch: d15-2
Build date: 2017-05-22 16:30:53-0400

Build Information
Release ID: 700010024
Git revision: 7ab1ca2ced6f584e56b7a0d4d321d00775cd95c9
Build date: 2017-05-19 05:44:51-04
Xamarin addins: 08d17158f3365beee5e60f67999e607cce4b3f93
Build lane: monodevelop-lion-d15-2

Operating System
Mac OS X 10.12.5
Darwin 16.6.0 Darwin Kernel Version 16.6.0
    Fri Apr 14 16:21:16 PDT 2017
    root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
Comment 1 Mugs 2017-05-30 17:00:59 UTC
I am facing the same issue.
If I use Don`t Link at link behavior it works, but the ipa file gets too big for publishing.

I have a Xamarin.Forms project, a Xamarin.iOs project, and a binding project. The error I get is when I try to access a class, that I have mapped on my binding project, on my Xamarin.iOS project. 

Its very simple to reproduce, create a binding library on xcode, create a Xamarin forms project with iOS, create a binding project on that solution, do the ApiDefinition, ex: 

   // Here is where you'd define your API definition for the native Objective-C library.
    // For example, to bind the following Objective-C class:
    //     @interface Widget : NSObject {
    //     }
    // The C# binding would look like this:
    //     [BaseType (typeof (NSObject))]
    //     interface Widget {
    //     }

and try to use that class or interface on your iOS project.
When using Link Sdk only it will throw a runtime error about JIT compile and AOT.
When using Don`t link it will work.
Comment 2 Zoltan Varga 2017-05-30 20:27:37 UTC
This seems to be caused by a linker or IL codegen failure:

    .custom instance void [Xamarin.iOS]Foundation.ExportAttribute::.ctor(string) = ( 01 00 04 69 6E 69 74 00 00 )                      // ...init..
    // Code size       94 (0x5e)
    .maxstack  3
    .locals init (bool V_0)
    IL_0000:  ldarg.0
    IL_0001:  ldsfld     class [Xamarin.iOS]Foundation.NSObjectFlag [Xamarin.iOS]Foundation.NSObjectFlag::Empty
    IL_0006:  call       instance void [Xamarin.iOS]Foundation.NSObject::.ctor(class [Xamarin.iOS]Foundation.NSObjectFlag)
    IL_000b:  nop
    IL_000c:  nop
    IL_000d:  ldarg.0
    IL_000e:  ldarg.0
    IL_000f:  call       instance class [mscorlib]System.Type [mscorlib]System.Object::GetType()
    IL_0014:  callvirt   instance class [mscorlib]System.Reflection.Assembly [mscorlib]System.Type::get_Assembly()
    IL_0019:  ldsfld     class [mscorlib]System.Reflection.Assembly ApiDefinition.Messaging::this_assembly
    IL_001e:  call       bool [mscorlib]System.Reflection.Assembly::op_Equality(class [mscorlib]System.Reflection.Assembly,
                                                                                class [mscorlib]System.Reflection.Assembly)
    IL_0023:  call       instance void [Xamarin.iOS]Foundation.NSObject::set_IsDirectBinding(bool)
    IL_0028:  nop
    IL_0029:  nop
    IL_002a:  nop
    IL_002b:  stloc.0

At 0x23, we do a call which returns void, then try to store it into a local.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-05-31 09:48:24 UTC
I'll have a look at this.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2017-05-31 11:48:22 UTC
I can reproduce with current stable (XI 10.10), but not with latest master.

This also looks very much like bug #53872 (which is already fixed in master), so I'm closing this as a duplicate of that bug.

*** This bug has been marked as a duplicate of bug 53872 ***
Comment 5 Jon Cortez 2017-05-31 20:09:47 UTC
Will this be fixed in the next stable update?
Comment 6 Rolf Bjarne Kvinge [MSFT] 2017-06-01 09:17:47 UTC
@Jon, yes, this will be fixed in the next major release (currently planned for some time in July I think).
Comment 7 Mugs 2017-06-01 13:21:48 UTC
What are the workarounds??? 
It was working, I have to publish a new version of my application and the "stable release" broke this.
Comment 8 Rolf Bjarne Kvinge [MSFT] 2017-06-01 14:56:51 UTC
@Mugs, if you elect "Enable optimization" [1] on the compiler (csc Windows) then this should also workaround the issue.

[1] `/optimize+` on the command line
Comment 9 Rolf Bjarne Kvinge [MSFT] 2017-06-01 14:57:48 UTC
*** Bug 56271 has been marked as a duplicate of this bug. ***
Comment 10 Mugs 2017-06-01 15:01:46 UTC
I tried to elect "Enable optimization" but my application would then crash on Release mode.
Comment 11 Rolf Bjarne Kvinge [MSFT] 2017-06-01 15:16:36 UTC
@Mugs, if you can provide a project I can use to reproduce this, I can have a look and try to find a workaround (but please open a new bug, so that we don't clutter this one).
Comment 12 Jon Cortez 2017-06-01 18:51:29 UTC
@Rolf, we cannot wait for the July release. It is probably easier to revert back to an earlier stable version of Xamarin. Would you know which version is that?
Comment 13 Rolf Bjarne Kvinge [MSFT] 2017-06-02 08:04:49 UTC
@Jon, here's how to downgrade: https://kb.xamarin.com/customer/portal/articles/1699777-how-do-i-downgrade-to-an-older-version-of-xamarin-

You'll want Xamarin.iOS 10.8 and Xamarin Studio 6.3.
Comment 14 danmiser 2017-07-12 16:48:35 UTC
Just to add here, I updated to the beta channel today. It has iOS I saw the problem in 10.10, but it seems to be fixed in 10.12. At least at first glance.
Comment 15 Jon Cortez 2017-08-07 16:58:33 UTC
The release seems late. It is already August. Any news on the release that includes the fix to this issue?
Comment 16 Rolf Bjarne Kvinge [MSFT] 2017-08-07 17:46:14 UTC
@Jon, I believe it'll be released tomorrow.
Comment 17 Rolf Bjarne Kvinge [MSFT] 2017-08-08 06:40:37 UTC
(In reply to Rolf Bjarne Kvinge [MSFT] from comment #16)
> @Jon, I believe it'll be released tomorrow.

I was mistaken, it's next week.