Bug 6681 - AOT does not generate constructor
Summary: AOT does not generate constructor
Status: RESOLVED FEATURE
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.3.x
Hardware: Other Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-08-24 11:38 UTC by Nezz
Modified: 2012-10-01 18:59 UTC (History)
2 users (show)

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

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:
Status:
RESOLVED FEATURE

Description Nezz 2012-08-24 11:38:03 UTC
I am workin on porting my game from WP7 to iOS using MonoGame. Everything loads fine in the simulator, but on an actual device (an iPad 2), I receive the following exception when a map is loading:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: Attempting to JIT compile method 'Microsoft.Xna.Framework.Content.NullableReader`1<Microsoft.Xna.Framework.Rectangle>:.ctor ()' while running with --aot-only.

  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00109] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:536
  --- End of inner exception stack trace ---
  at System.Reflection.MonoCMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0011f] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:542
  at System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:551
  at System.Reflection.ConstructorInfo.Invoke (System.Object[] parameters) [0x0000e] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Reflection/ConstructorInfo.cs:62
  at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders () [0x0011f] in /Users/turtlegames/Documents/Development/MonoGame/MonoGame.Framework/Content/ContentTypeReaderManager.cs:131
  at Microsoft.Xna.Framework.Content.ContentReader.InitializeTypeReaders () [0x0000c] in /Users/turtlegames/Documents/Development/MonoGame/MonoGame.Framework/Content/ContentReader.cs:111
  at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[Map] () [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[Map] (System.String assetName, System.Action`1 recordDisposableObject) [0x00000] in <filename unknown>:0
  at Microsoft.Xna.Framework.Content.ContentManager.Load[Map] (System.String assetName) [0x00000] in <filename unknown>:0
  at TurtleGames.RumRun.GameScreen.MapForm.Load (TurtleGames.RumRun.SaveSystem.Box box) [0x00047] in /Users/turtlegames/Documents/Development/MonoDevelop/TurtleGames.RumRun/TurtleGames.RumRun/Screens/GameScreen/MapForm/MapForm.cs:100
[...]

It fails to invoke the ctor for the following type reader:
Microsoft.Xna.Framework.Content.NullableReader`1[[Microsoft.Xna.Framework.Rectangle, Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553]]

All my other custom type readers seem to be working, except for the this one.

I appreciate any help you can give me, regarding this issue :)
Comment 1 Sebastien Pouliot 2012-08-24 13:14:52 UTC
It could be two things:

a) reflection is being used. It's possible that the linker removed the type because it seemed unused. Try disabling (Don't link) the application (on devices) or enabling linking (on the simulator). However, since those are "user" types I do not think this is your issue;

b)  The AOT compiler has some limitations [1] when generics are used with value-types. IIRC Microsoft.Xna.Framework.Rectangle is a struct.

In both cases a solution is to make sure the type exists (without reflection) and is used (so it's not linked away) inside your application. That might give the hints required for the AOT compiler to generate the code.

[1] http://docs.xamarin.com/ios/about/limitations#Limited_Generics_Support
Comment 2 Nezz 2012-10-01 18:59:24 UTC
I see that it is a limitation.