entity-framework-coremauiclass-libraryahead-of-time-compile

Failed to AOT compile MyLibrary.dll, the AOT compiler exited with code 1 (ProjectName)


I have a MAUI application (.NET 7) referencing a custom class library (.dll) with an EF Core infrastructure (.NET 6) which nicely compiles and deploys in Debug mode on all platforms. Unfortunately, when I try to compile and pack it I get the following error:

/usr/local/share/dotnet/packs/Microsoft.MacCatalyst.Sdk/16.2.1040/targets/Xamarin.Shared.Sdk.targets(1011,3): error : Failed to AOT compile MyLibrary.dll, the AOT compiler exited with code 1 1 Error(s)

or a similar one on Android or MacCatalyst.

Is there any option I am missing to deactivate AOT Compilation? Can I deactivate it since I also have to pack it for iOS devices? Or should I change something on the library project itself to make it fitting to be AOT compiled?


Solution

  • There is an existed issue about Aot compilation fail when publishing for iOS. It has the same error message as yours.

    And you can try the workaround in the comment, using the following code in the csproj.file.

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
    <MtouchUseLlvm>False</MtouchUseLlvm>
    <AotAssemblies>True</AotAssemblies>
    </PropertyGroup>
    

    In addition, if you can share your project on the github, you can also post an new issue and post your project as the sample.

    Update 1:

    Add the following code to your csproj:

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