sillsdev / sillsdev/languageforge-lexbox

MacOS dotnet publish results in NativeAOT error

Open
#1,603 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

💻 FW Lite bug
Dominant language
C#
Stars
9
Forks
8
Avg merge
2d 13h
Merged PRs (30d)
49

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

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the dotnet publish -f net9.0-maccatalyst result and inspect the Entity Framework Core DbContext project. Review the attempted Microsoft.EntityFrameworkCore.Design installation and dotnet ef migrations bundle --self-contained false --force command, including whether it targets the project containing the DbContext. Done means the published FwLiteMaui.app no longer shows the model-building runtime error.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
databases, mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.