Skip to content

MacOS dotnet publish results in NativeAOT error #1603

@megahirt

Description

@megahirt

Describe the bug
When doing a dotnet publish -f net9.0-maccatalyst the resulting FwLiteMaui.app MacOS app is runnable, however there is a runtime error that shows in the application window that says:

Model building is not supported when publishing with NativeAOT. Use a compiled model.

Error: System.InvalidOperationException: Model building is not supported when publishing with NativeAOT. Use a compiled model. at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime) at 
Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model() at 
Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.
<TryAddCoreServices>b__8_4(IServiceProvider p) at 
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite , 
RuntimeResolverContext ) at 
Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.Serv
iceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=9.0.0.0, Culture=neutral, 
PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=9.0.0.0, Culture=neutral, 
PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite ,

(I trimmed the stack-trace)

Screenshot

Image

I asked AI about this problem and it is saying that dotnet publish for mac catalyst defaults to NOT use NativeAOT. Further inspection and an explicit -p:PublishAot=false lead me to believe that the published .app is not using NativeAOT but that there is something else going on with EntityFramework in this context that is AOT-like.

AI suggested that I could compile the models at build time like this:

dotnet add package Microsoft.EntityFrameworkCore.Design

followed by

dotnet ef migrations bundle --self-contained false --force

The ef migration command failed with no error message that I could find. I pretty much ran out of time on this, but AI suggested at this point to try and point the ef migrations command at the project that contains the DbContext. This sort of makes sense but I'm less confident at proceeding further at this point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working💻 FW Liteissues related to the fw lite application, not miniLcm or crdt related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions