Search code examples
.netreleasemauiassembliesahead-of-time-compile

.NET 6 Library referenced in MAUI project fails to compile in Release configuration with AOT error


I have a MAUI project which references a .NET 6 Class Library (itself including an EF Core context with related NuGet packages and all the model objects). This class is referenced as a .NET Assembly within the MAUI project.

As long as I keep on compiling and executing in Debug configuration everything works fine on each and every platform. As long as I switch to Release (or any other publish-oriented configuration), compiling and deploying fails claiming that AOT is not able to compile the assembled .NET assembly because of the inner references to EF Core.

This error: "AOT Compilation exited with code 1" would pop out while both compiling in Release configuration on Android or iOS.

I am using VS for MAC Silicon and I can't find no option to disable AOT. Additionally, disabling it would prevent me from publishing and archiving on iOS and MacCatalyst which I would really like to do asap.

As an additional information, I can't reference the class library project itself since it's contained in a different solution (an API Rest Web Service).

How can I use the same class library without running into this issues with AOT?


Solution

  • Try adding this property to your Release (or whatever) configuration markup:

    <PropertyGroup> <UseInterpreter>true</UseInterpreter> </PropertyGroup>

    This should do the trick!