efcore: MAUI Blazor - database no longer works in Android Release mode
Description
After upgrading EF Core (sqlite) from 8.0.0-preview.6.23329.4
to 8.0.0-rc.1.23419.6
my app now throws when using the database in Android Release mode. It’s fine on Android Debug and Windows Debug/Release.
You’ll see in the attached log that it’s observable at the await dbSeeder.SeedAsync()
call in Index.OnInitializedAsync()
.
Steps to Reproduce
- Clone repo
- Run on Android emulator in Release mode
An error occurred with the app
during the loading screen
Link to public reproduction project repository
https://github.com/danielchalmers/JournalApp
Affected platforms
Android
Relevant log output
10-10 16:45:18.155 23621 23644 I DOTNET : fail: JournalApp.Index[0]
10-10 16:45:18.155 23621 23644 I DOTNET : database error
10-10 16:45:18.155 23621 23644 I DOTNET : System.ArgumentNullException: ArgumentNull_Generic Arg_ParamName_Name, source
10-10 16:45:18.155 23621 23644 I DOTNET : at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument )
10-10 16:45:18.155 23621 23644 I DOTNET : at System.Linq.Enumerable.Count[IReadOnlyForeignKey](IEnumerable`1 source)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetDefaultColumnName(IReadOnlyProperty property)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetDefaultColumnName(IReadOnlyProperty property, StoreObjectIdentifier& storeObject)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetColumnName(IReadOnlyProperty property, StoreObjectIdentifier& storeObject)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.RelationalPropertyExtensions.GetMappedStoreObjects(IReadOnlyProperty property, StoreObjectType storeObjectType)+MoveNext()
10-10 16:45:18.155 23621 23644 I DOTNET : at System.Linq.Enumerable.TryGetFirst[StoreObjectIdentifier](IEnumerable`1 source, Boolean& found)
10-10 16:45:18.155 23621 23644 I DOTNET : at System.Linq.Enumerable.FirstOrDefault[StoreObjectIdentifier](IEnumerable`1 source)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.RelationalValueGenerationConvention.GetValueGenerated(IConventionProperty property)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.ValueGenerationConvention.ProcessForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder, IConventionContext`1 context)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnForeignKeyAdded(IConventionForeignKeyBuilder relationshipBuilder)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnForeignKeyAddedNode.Run(ConventionDispatcher dispatcher)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.DelayedConventionScope.Run(ConventionDispatcher dispatcher)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose()
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelInitialized(IConventionModelBuilder modelBuilder)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelInitialized(IConventionModelBuilder modelBuilder)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Metadata.Internal.Model..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.ModelBuilder..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.ModelConfigurationBuilder.CreateModelBuilder(ModelDependencies modelDependencies)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel(Boolean designTime)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__8_4(IServiceProvider p)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite , RuntimeResolverContext )
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-10 16:45:18.155 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite , RuntimeResolverContext , ServiceProviderEngineScope , RuntimeResolverLock )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite , RuntimeResolverContext )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=8.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite , ServiceProviderEngineScope )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier , ServiceProviderEngineScope )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider , Type )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IDbContextDependencies](IServiceProvider )
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
10-10 16:45:18.156 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService(IInfrastructure`1 accessor, Type serviceType)
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[IDatabaseFacadeDependencies](IInfrastructure`1 accessor)
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[IDatabaseFacadeDependencies](IInfrastructure`1 accessor)
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_Dependencies()
10-10 16:45:18.157 23621 23644 I DOTNET : at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()
10-10 16:45:18.157 23621 23644 I DOTNET : at JournalApp.ApplicationDbSeeder.SeedAsync()
10-10 16:45:18.157 23621 23644 I DOTNET : at JournalApp.Index.OnInitializedAsync()
About this issue
- Original URL
- State: open
- Created 9 months ago
- Reactions: 5
- Comments: 34 (7 by maintainers)
Commits related to this issue
- Log database EnsureCreated errors https://github.com/dotnet/efcore/issues/32040 — committed to danielchalmers/JournalApp by danielchalmers 8 months ago
- Revert EF Core to working version Any version after preview 6 results in a crash in Release mode on Android https://github.com/dotnet/efcore/issues/32040 — committed to danielchalmers/JournalApp by danielchalmers 8 months ago
Putting my vote in here for this to be repaired in an 8.x service release please, this is forcing us to deliver Debug builds for our Android clients or split code logic paths for Android specifically when interacting with SQLite, this feels like this should be higher priority if at all possible.
The root cause seems to be same as in https://github.com/dotnet/runtime/issues/96264
Note for triage: Even with AOT and trimming disabled, this still fails in Release mode but works in Debug mode. It’s not clear to me there is anything we can do here, other than report back again if this still doesn’t work when trimming and AOT are fully supported.
I second this, .NET MAUI with EF core and SQLite, doesn’t work in release mode, does work in debug mode.
I’m running into this issue even when the project is compiled in Debug mode. This is on a .NET Android project using EFCore 8.0.0 Downgrading to EFCore 7.0.14 does fix the problem.
I get the following stack trace. Looking at the EFCore source it appears it’s trying to access a list of foreign keys. The queries that throw this error use entities that have no foreign keys. It could be just adding a simple null check could fix this problem?
I noticed that this bug is added to the 9.0.0 milestone. Is the plan to leave this broken until EFCore 9.0 is released?
android.runtime.JavaProxyThrowable: [System.ArgumentNullException]: Value cannot be null. (Parameter 'source') at System.Linq.ThrowHelper.ThrowArgumentNullException(Unknown Source:0) at System.Linq.Enumerable.All(Unknown Source:0) at Microsoft.EntityFrameworkCore.Metadata.Conventions.ValueGenerationConvention.GetValueGenerated(Unknown Source:0) at Microsoft.EntityFrameworkCore.Metadata.Conventions.RelationalValueGenerationConvention.GetValueGenerated(Unknown Source:0)
First, compiled model doesn’t work: https://github.com/dotnet/efcore/issues/32346
Second, here is a repo: https://github.com/pekspro/MauiIssues/tree/EfCore32040
It’s a very simple application with a simple dbcontext and instructions how to build for Android where I’m having this issue. Windows in release mode seems to be fine.
Here is the stack trace:
Here’s a variant of the error that I get: