Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maui workload 8.0.61/8.0.100 introduced NativeAOT runtime error in EFC .net 8 #23595

Closed
chrisweihu opened this issue Jul 13, 2024 · 11 comments
Closed
Labels
platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working

Comments

@chrisweihu
Copy link

Description

We use Azure DevOps Pipeline to build Maui .Net 8 iOS app. This runtime error is throw by EF.Sqlite .net 8 when calling DbContext.Migrate(). The error started to occur yesterday with no yaml change in our azure build pipeline.
Here is the runtime error message:

Exception:Model building is not supported when publishing with NativeAOT. Use a compiled model.,
InnerException:, StackTrace: at Microsoft.EntityFramework-Core.Internal.DbContextSer-vices.CreateModel(Boolean
designTime)

I found this answer stating that the NativeAOT publishing is not yet supported on EFC .net 8.

We compared the Installed .NET SDK and MAUI workload version on Azure MAUI build Pipeline between Wednesday (No error) and Friday(Has NativeAOT error):
Both builds installed .NET SDK: 8.0.300
Wednesday (No error) - installed maui workload 8.0.40/8.0.100
Friday(Has NativeAOT error) - installed maui workload 8.0.61/8.0.100

It looks like maui workload 8.0.61 has introduced the EF NativeAOT error. I have not found a working solution that allows us to install specified maui workload version.

I have tried the following work-arounds, but no luck so far:

  1. install maui workload with specific version using '--from-rollback-file'
    dotnet workload install maui --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/8.0.1xx.json --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json --source https://api.nuget.org/v3/index.json
    This will fail with message:
    Workload installation failed: Failed to install manifest microsoft.net.sdk.maui version 8.0.4: Version 8.0.4 of package microsoft.net.sdk.maui.manifest-8.0.100 is not found in NuGet feeds [https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json"..]

  2. Add <PublishAot>false</PublishAot> to Maui project to disable Publish AOT

Steps to Reproduce

Create a Maui iOS azure build pipeline using the following YAML configuration:

variables:
- name: BuildParameters.serverEndpoint
  value: [xxx]
- name: BuildParameters.configuration
  value: Release
- name: BuildConfiguration
  value: Release
- name: BuildPlatform
  value: iPhone
- name: iOScertPassword
  value: [xxx]
- name: system.debug
  value: false
name: $(date:yyyyMMdd)$(rev:.r)
stages:
- stage: __default
  jobs:
  - job: Phase_1
    displayName: Phase 1
    cancelTimeoutInMinutes: 1
    pool:
      name: Azure Pipelines
      vmImage: 'macos-14'
    steps:
    - task: CmdLine@2
      inputs:
        script: |
          sudo xcode-select -s /Applications/Xcode_15.4.app
          xcrun xcode-select --print-path
          xcodebuild -version
    - task: NuGetToolInstaller@1
      inputs:
        versionSpec: '6.9.1'

    - task: UseDotNet@2
      displayName: 'Install .NET sdk'
      inputs:
        packageType: sdk
        version: 8.0.300
        installationPath: $(Agent.ToolsDirectory)/dotnet
    - task: InstallAppleCertificate@2
      displayName: Install an Apple certificate
      inputs:
        certSecureFile: '[xxx].p12'
        certPwd: [xxx]
        deleteCert: false
        deleteCustomKeychain: false
        setUpPartitionIdACLForPrivateKey: false
    - task: InstallAppleProvisioningProfile@1
      displayName: Install an Apple provisioning profile
      inputs:
        provisioningProfileLocation: 'secureFiles'
        provProfileSecureFile: '[xxx].mobileprovision'
    - task: NuGetCommand@2
      name: NuGetCommand2
      displayName: NuGet restore BGC.Cambio.Mobile.sln
      inputs:
        command: 'restore'
        restoreSolution: '[xxx]Mobile.sln'
        feedsToUse: 'select'
        includeNuGetOrg: true
        noCache: true
      enabled: False
    - task: Bash@3
      displayName: 'Install Maui Workload'
      inputs:
        targetType: 'inline'
        script: |
          dotnet nuget locals all --clear          
          dotnet workload install maui --source https://api.nuget.org/v3/index.json
          
    - task: CmdLine@2
      inputs:
        script: |
          echo dotnet --info:
          dotnet --info
          echo dotnet workload --info:
          dotnet workload --info
    - task: DotNetCoreCLI@2
      displayName: 'Build the iOS Binaries'
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '[xxx].MAUI.csproj'
        arguments: '-f:net8.0-ios -c:Release /p:ArchiveOnBuild=true /p:EnableAssemblyILStripping=false --source https://api.nuget.org/v3/index.json'
        zipAfterPublish: false
    - task: CopyFiles@2
      displayName: 'Copy file from Build to Staging'
      inputs:
        SourceFolder: '$(Agent.BuildDirectory)'
        Contents: '**/*.ipa'
        TargetFolder: '$(Build.ArtifactStagingDirectory)'
        CleanTargetFolder: true
        OverWrite: true
    - task: PublishBuildArtifacts@1
      displayName: 'Publish the Staging Files.'
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'


Create a MAUI project that use "Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4". It should contains a code either call DbContext.Database.Migrate() or DbContext.Database.EnsureCreated().

Install the build onto a iOS device (don't use simulator)

App crashes when DbContext.Database.Migrate() or DbContext.Database.EnsureCreated() is called.

Link to public reproduction project repository

No response

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.40 SR5

Affected platforms

iOS

Affected platform versions

iOS 17

Did you find any workaround?

NO

Relevant log output

No response

@chrisweihu chrisweihu added the t/bug Something isn't working label Jul 13, 2024
@bengavin
Copy link

We're running into this same issue, I was guessing that it was related to the UseInterpreter changes that went into the latest xamairn-macios library (https://github.com/xamarin/xamarin-macios/releases/tag/dotnet-8.0.1xx-8078)

I'll post if I find any more information or workarounds, but this is blocking us from releasing at the moment.

@PureWeen
Copy link
Member

Can you create and attach a binlog please?
https://github.com/dotnet/maui/wiki/Capturing-Binary-Logs

@bengavin
Copy link

Working on getting a local build to generate the same error, but if that doesn't work out, I'll add the argument to our automated builds.

@timlajaunie
Copy link

We're running into this same issue, I was guessing that it was related to the UseInterpreter changes that went into the latest xamairn-macios library (https://github.com/xamarin/xamarin-macios/releases/tag/dotnet-8.0.1xx-8078)

I'll post if I find any more information or workarounds, but this is blocking us from releasing at the moment.

This may be related to #23577.

@samhouts samhouts added platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending labels Jul 15, 2024
@bengavin
Copy link

Tweaking the MtouchInterpreter value on the DevOps build ends up 'locking up' the build on the hosted agents, it pauses indefinitely with no progress and eventually gets killed by the devops infrastructure, no amount of cancelling through the UI is effective. Local builds complete successfully, but resulting executable crashes on launch prior to doing anything (I think this is related to local config/permissions/etc). If I'm able to convince DevOps to give me a log, I'll try to post it, but I'm coming up empty at the moment.

@bengavin
Copy link

ok, adding the following to our dotnet build command allowed the build to process through and appears at first glance to stop the crashing:

dotnet build ... -p:MtouchInterpreter=all -p:UseInterpreter=true -p:MtouchLink=None

This is, I think, equivalent to the behavior prior to this latest iOS workload release, so it's fine for now, but would be good to figure out how to get some of the benefit of AOT while still carving out the interpreter for things like EFCore.

@RuddyOne
Copy link

Also having this issue, is there a way to install the old version of the workloads.

Didn't realise this was the issue and been fighting it for 2 days.

@samhouts
Copy link
Member

Duplicate of #23577

@samhouts samhouts marked this as a duplicate of #23577 Jul 16, 2024
@jdngray77
Copy link

@RuddyOne Yes, you can use a rollback file - though i believe it's not officially supported. Useful for a temporary workaround though.

dotnet workload install maui-maccatalyst --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/8.0.40.json

@RuddyOne
Copy link

@RuddyOne Yes, you can use a rollback file - though i believe it's not officially supported. Useful for a temporary workaround though.

dotnet workload install maui-maccatalyst --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/8.0.40.json

Thank you for that, useful info.

I have ended up with @bengavin workaround at the moment, not sure if there is a downside though. Might look at changing to this rollback for now.

Much appreciated.

@DonkeyKongJr
Copy link

I guess we have the same problem: #23653

@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

8 participants