0

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?

1 Answers1

1

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>
Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • Thanks for the suggestion. I tried with a brand new template MAUI project but applying it unfortunately didn’t work. To make the situation more complicated, I’m using Vs for Mac and the section “Configurations” within the project properties isn’t that user-friendly :/ dunno what else to do if not to open an issue on GitHub as you said… – ImproveSoftware Apr 13 '23 at 05:18
  • Did you try to disable the Aot with `False`? @ImproveSoftware – Liyun Zhang - MSFT Apr 13 '23 at 05:22
  • And did you change the `'Release|net6.0-ios|AnyCPU'` to `'Release|net7.0-ios|AnyCPU'`? I see you said your project is .net 7.0. @ImproveSoftware – Liyun Zhang - MSFT Apr 13 '23 at 05:42
  • Yes, of course I swapped to 'Release|net7.0-ios|AnyCPU' and I tried with disabling the AOT using the markup you suggested but with no luck. I also tried with a suggested (as a warning) different markup to disable AOT compiling which is "RunAOTCompilation" that should be replacing "AotAssemblies", but I get even more errors. The issue keeps on being the referenced assembly that fails to AOT compile (it's a peaceful .NET 6 with EF Core context class library). – ImproveSoftware Apr 13 '23 at 06:42
  • Maybe you can try to set your project's target framework as .net 6.0. Because the EF Core context class library is .net 6.0. @ImproveSoftware – Liyun Zhang - MSFT Apr 13 '23 at 06:45
  • I’ll give it a try asap and let you know. By the way, should a .NET 6 class library not be compliant with a .NET 7 project (especially if the involved nuget packages support the used workloads)? Am I wrong? – ImproveSoftware Apr 13 '23 at 06:52
  • All right, waiting for your feedback. @ImproveSoftware – Liyun Zhang - MSFT Apr 13 '23 at 09:49
  • I tried everything you suggested with no luck. Enabled and disabled several options both in the original project or in a new template one. I even tried with a brand new configuration. Despite sometimes it builds in Release mode, it can’t publish whether I proceed by CLI or by IDE. And the error I get is always the same (the one in the topic). I’m seriously thinking about abandoning that library at all. Just to give you more information, I’m using Vs for Mac Silicon. Dunno what else to do :/ – ImproveSoftware Apr 13 '23 at 18:02
  • After three more hours spent to figure it out I came out with this: it would compile and run in release configuration if I set the linker of the specific platform to “Link All”. This would allow me to publish the application properly. However, while I was testing the published version against a web service I noticed that the models (or in general the objects) contained in the referenced external class library aren’t properly constructed. This of course causes a number of problems. Can this weird behavior be someway related to the settings in the linker? I’m very desperate :( – ImproveSoftware Apr 13 '23 at 23:18
  • Which version of xcode did you use? And did you publish the project with the Visual Studio for mac of the vs for windows? @ImproveSoftware – Liyun Zhang - MSFT Apr 14 '23 at 05:30
  • XCode is 14.3 (latest version) but it happened with XCode 14.2 as well. No I only have Vs for Mac since I don’t have any Windows machine. – ImproveSoftware Apr 14 '23 at 06:02
  • Did you try to publish a template project without the custom class library (.dll)? @ImproveSoftware – Liyun Zhang - MSFT Apr 14 '23 at 06:06
  • Yes and it works properly. – ImproveSoftware Apr 14 '23 at 06:12
  • So the cause is the custom library. You can try to add the ` true ` into the csproj.flie accoding to [this issue on the github](https://github.com/dotnet/maui/issues/9597#issuecomment-1225557647). @ImproveSoftware – Liyun Zhang - MSFT Apr 14 '23 at 06:18
  • Leaving the custom properties of Release configuration (link SDKs Assemblies only) but setting the interpreter to TRUE made the trick! The compiled executable (for MacCatalyst) is lighter and seems to work properly. The AOT compiler isn’t failing any longer (despite I didn’t disable it). I was even able to publish for iOS. Thanks for your good help, I don’t actually know why I had to go through this! :) – ImproveSoftware Apr 14 '23 at 07:29
  • Did you mean the code `true ` resolved this problem? @ImproveSoftware – Liyun Zhang - MSFT Apr 14 '23 at 07:32
  • I confirm that adding `true ` solved the AOT compiling issue on iOS and MacCatalyst. – ImproveSoftware Apr 14 '23 at 07:50
  • All right, glad to know you resolved the problem. Happy coding! – Liyun Zhang - MSFT Apr 14 '23 at 08:03