I am interested in NativeAOT after reading this article.
Using the article as a reference, I tried to do native publish with .NET 6.0 using the current MonoGame Version 220.127.116.113 and VS2022, but the native binaries do not build.
Microsoft.DotNet.ILCompiler version is 7.0.0 and it references rd.xml from the project.
It did not work in an empty DesktopGL project, nor in the following repository
Is native publish possible with the current MonoGame version?
Unfortunately, we did not get any help from anyone, but we were able to solve the problem on our own.
Finding the following web page was the solution. Thank you very much.
04:05PM - 29 Mar 23 UTC
Fresh MonoGame project is failing to load content after publishing with `<Publis
… hAot>true</PublishAot>` property enabled with the following error:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Xna.Framework.Content.ContentTypeReaderManager.LoadAssetReaders(ContentReader) + 0x938
at Microsoft.Xna.Framework.Content.ContentReader.InitializeTypeReaders() + 0x40
at Microsoft.Xna.Framework.Content.ContentReader.ReadAsset[T]() + 0x20
at Microsoft.Xna.Framework.Content.ContentManager.ReadAsset[T](String, Action`1) + 0xa4
at Microsoft.Xna.Framework.Content.ContentManager.Load[T](String assetName) + 0xa8
at Game1.SampleGame.LoadContent() + 0x124
at Game1.SampleGame.Initialize() + 0x60
at Microsoft.Xna.Framework.Game.DoInitialize() + 0x60
at Microsoft.Xna.Framework.Game.Run(GameRunBehavior) + 0xbc
at Program.<Main>$(String args) + 0x48
Because I'm using M1, I'm also using 8.0 version of ILCompiler to target `osx-arm64`:
<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="8.0.0-*" />
Any other compatible with the NativeAOT app is working fine with such a setup.
### System info
- System Version: macOS 13.2.1 (22D68)
- Kernel Version: Darwin 22.3.0
- Boot Volume: Macintosh HD
- Model Name: MacBook Pro
- Model Identifier: MacBookPro18,2
- Model Number: MK1A3ZE/A
- Chip: Apple M1 Max
- Total Number of Cores: 10 (8 performance and 2 efficiency)
- Memory: 32 GB
- System Firmware Version: 8419.80.7
- OS Loader Version: 8419.80.7
#### What version of MonoGame does the bug occur on:
- MonoGame 3.8.1
#### What operating system are you using:
- Mac OS X 13.2.1 (M1)
#### What MonoGame platform are you using:
I have published a sample project and documentation on GitHub, and I would be happy to help anyone who has trouble with something similar.
Interesting. I’ve been interested in NativeAOT for potential performance benefits, but it’s incompatible with DirectX builds due to the use of Windows Forms.
Thanks for reading.
Yes, It is unfortunate that DirectX builds cannot work with NativeAOT at this time. I hope and pray that future versions of .NET.
Pray for MG to stop using winforms in DirectX project, that’s way better as it is causing more issues than just AoT.