-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
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

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.