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

Microsoft.EntityFrameworkCore.Sqlite 7 crash on iOS #16228

Closed
rolfbjarne opened this issue Oct 4, 2022 · 52 comments
Closed

Microsoft.EntityFrameworkCore.Sqlite 7 crash on iOS #16228

rolfbjarne opened this issue Oct 4, 2022 · 52 comments
Labels
bug If an issue is a bug or a pull request a bug fix
Milestone

Comments

@rolfbjarne
Copy link
Member

From @RobertoGFilho on Thu, 18 Aug 2022 11:03:24 GMT

EfCore 7 crash on iOS MAUI app. Please you can reproduce this erro on this demo : https://github.com/RobertoGFilho/EFCore

  • Windows ok
  • Android ok
  • iOS crash

image

Visual studio 17.3.1
Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0-preview.7.22376.2"

Copied from original issue dotnet/efcore#28773

@rolfbjarne
Copy link
Member Author

From @eerhardt on Thu, 18 Aug 2022 23:42:07 GMT

I don't believe this is a NullabilityInfoContextSupport issue. When I ran your app I see the following exception being thrown:

image

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Fri, 19 Aug 2022 12:18:28 GMT

@eerhardt thanks for you attention!

I'm using Visual Studio 17.3.1 for Windows 11 and real device iPhone 7plus with hotrestart. Only iOS this error happen! I have already worked with EFCore 3.1 and Xamarin for three plataforms and works well.

On Xamarin configuration iOS is:

    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        SQLitePCL.Batteries_V2.Init();
        global::Xamarin.Forms.Forms.Init();

        var libPath = Path.Combine(
            System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments),
            "..", "Library", "data");

        if (!Directory.Exists(libPath))
        {
            Directory.CreateDirectory(libPath);
        }

        var dbPath = Path.Combine(libPath, "core.sqlite");
        LoadApplication(new App(dbPath));
        return base.FinishedLaunching(app, options);
    }

let me show what is happen on MAUI:

2022_08_19_09_02_50.mp4

I've already add : NullabilityInfoContextSupport = true on project file but it doesn't work

image

do you have any idea?

@rolfbjarne
Copy link
Member Author

From @eerhardt on Fri, 19 Aug 2022 16:22:42 GMT

Can you list what version of dotnet and the MAUI workload you are using?

dotnet --info
dotnet workload list

I'm using a mac with 6.0.400 of the dotnet SDK and 6.0.486/6.0.400 of the maui workload.

When running the app on an iPad simulator in Debug mode, the app works fine. When running with -c Release, I get the above exception.

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Fri, 19 Aug 2022 20:39:34 GMT

@eerhardt

I'm using 6.0.8

image

I'm using a real device "iPhone 7" plus iSO version 15 .. in debug mode .. and hotrestar enable

@rolfbjarne
Copy link
Member Author

From @eerhardt on Fri, 19 Aug 2022 20:44:22 GMT

What is the output of dotnet workload list?

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Fri, 19 Aug 2022 21:00:45 GMT

Installed Workload Ids Manifest Version Installation Source

maui-android 6.0.486/6.0.400 VS 17.3.32811.315
android 32.0.448/6.0.400 VS 17.3.32811.315
maui-windows 6.0.486/6.0.400 VS 17.3.32811.315
maui-maccatalyst 6.0.486/6.0.400 VS 17.3.32811.315
maccatalyst 15.4.446-ci.-release-6-0-4xx.446/6.0.400 VS 17.3.32811.315
maui-ios 6.0.486/6.0.400 VS 17.3.32811.315
ios 15.4.446-ci.-release-6-0-4xx.446/6.0.400 VS 17.3.32811.315

Use dotnet workload search to find additional workloads to install.

@rolfbjarne
Copy link
Member Author

From @eerhardt on Wed, 24 Aug 2022 20:33:25 GMT

Unfortunately, I can't repro this behavior.

If I launch the app on a physical phone using VS for Mac, it works correctly. I don't see an exception being thrown.

I'm not able to deploy any Maui app to a physical phone from VS on Windows for some reason, and I spent too much time trying to get it to work. I've given up.

My suggestions for debugging this would be to get a binlog of the build and inspect the ILLink task to see what parameters are getting passed to the linker. I don't know why these would be different for iOS vs. Android. Maybe something on your machine is telling it to use different settings.

If a binlog doesn't help, inspecting the .dlls in something like ILSpy may help give a clue. Look for the code using this switch:

https://github.com/dotnet/runtime/blob/e71a9583b4d6c9bd97edd87cda7f98f232f63530/src/libraries/System.Private.CoreLib/src/System/Reflection/NullabilityInfoContext.cs#L20-L21

@rolfbjarne
Copy link
Member Author

From @eerhardt on Wed, 24 Aug 2022 22:11:14 GMT

Another thing to look for is in the "Build" output (on a fresh build/install), look for the string System.Reflection.NullabilityInfoContext.IsSupported. This should be set to true. If you see it set to false, that's the issue.

Here's a snippet of my build output:

1>/Users/eerhardt/Library/Caches/Xamarin/XMA/SDKs/dotnet/dotnet "/Users/eerhardt/Library/Caches/Xamarin/XMA/SDKs/dotnet/sdk/6.0.400/Sdks/Microsoft.NET.ILLink.Tasks/build/../tools/net6.0/illink.dll" -a "obj/Debug/net6.0-ios/ios-arm64/EFCore.dll"
1>-a "obj/Debug/net6.0-ios/ios-arm64/EFCore.dll"
1>-reference "C:/Users/eerhardt/.nuget/packages/microsoft.data.sqlite.core/7.0.0-preview.7.22376.2/lib/net6.0/Microsoft.Data.Sqlite.dll"
1>-reference "C:/Users/eerhardt/.nuget/packages/microsoft.entityframeworkcore/7.0.0-preview.7.22376.2/lib/net6.0/Microsoft.EntityFrameworkCore.dll"
...
1>--warn "5"
1>--warnaserror- --warnaserror ";NU1605"
1>--feature Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability true
1>--feature System.AggressiveAttributeTrimming true
1>--feature System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization false
1>--feature System.Diagnostics.Debugger.IsSupported true
1>--feature System.Diagnostics.Tracing.EventSource.IsSupported false
1>--feature System.Globalization.Invariant false
1>--feature System.Net.Http.EnableActivityPropagation false
1>--feature System.Net.Http.UseNativeHttpHandler true
1>--feature System.Reflection.NullabilityInfoContext.IsSupported true

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Thu, 25 Aug 2022 12:11:56 GMT

hey @eerhardt ! something very crazy is happen! When I use iOS emulator error disappear, but if i try real device "iPhone 7 Plus" happens error . see:

2022_08_25_09_10_06.mp4

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Thu, 25 Aug 2022 12:13:37 GMT

I have tryed to change : System.Reflection.NullabilityInfoContext.IsSupported = true or false.. but error happens

@rolfbjarne
Copy link
Member Author

From @eerhardt on Thu, 25 Aug 2022 14:40:49 GMT

but if i try real device "iPhone 7 Plus" happens error .

I've run the EFCore app both from VS for Mac preview on my mac, and from VS for Windows paired with my mac, to a physical iPhone 6S and can't repro this behavior.

Can you try running the app on a different development machine? My guess is that there is something specific about your dev machine that is causing this.

@rolfbjarne
Copy link
Member Author

From @eerhardt on Thu, 25 Aug 2022 14:44:12 GMT

One idea to try to figure this out:

  1. Delete the app from the physical device. and "Clean" the project. Delete the bin and obj folders to ensure everything is clean.
  2. Follow the steps in https://docs.microsoft.com/en-us/visualstudio/ide/msbuild-logs?view=vs-2022#create-a-binary-msbuild-log-by-using-the-project-system-tools-extension to get a binlog of the build that happens when you deploy to the physical phone.
  3. Attach the binlogs here.

The only thing I can guess is that somehow the System.Reflection.NullabilityInfoContext.IsSupported switch is getting set to false by something, but I'm not sure what. The binlog would tell us who/what is setting it.

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Mon, 05 Sep 2022 13:32:09 GMT

hi @eerhardt same error here on iPhone 6S Plus and 7Plus, on real device

@rolfbjarne
Copy link
Member Author

From @eerhardt on Tue, 06 Sep 2022 15:38:32 GMT

@RobertoGFilho - did you try the above to get a binlog?

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Sat, 10 Sep 2022 22:14:06 GMT

hi folks!
the trouble is string properties on Model! see:

WORKS:

public class Person : ObservableObject
{
[Key]
public Guid Id { get; set; }
public int Age { get; set; }
//public string Name { get; set; }
}

DOESN'T WORK

public class Person : ObservableObject
{
[Key]
public Guid Id { get; set; }
public int Age { get; set; }
public string Name { get; set; }
}

@rolfbjarne
Copy link
Member Author

From @ErikEJ on Sun, 11 Sep 2022 06:08:15 GMT

What is ObservableObject?

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Mon, 12 Sep 2022 11:22:29 GMT

hi @ErikEJ ,

ObservableObject is from MVVMHelpers, you can remove this, but the same error will show up! This error happen only string properties on Model. Only iOS plataform.

Please you can reproduce this erro on this demo : https://github.com/RobertoGFilho/EFCore

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Mon, 12 Sep 2022 11:58:26 GMT

[0:] NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.
[0:] An error occurred: 'NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.'. Callstack: '   at System.Reflection.NullabilityInfoContext.EnsureIsSupported()
   at System.Reflection.NullabilityInfoContext.Create(PropertyInfo propertyInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableConventionBase.IsNonNullableReferenceType(IConventionModelBuilder modelBuilder, MemberInfo memberInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.Process(IConventionPropertyBuilder propertyBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext`1 context)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnPropertyAdded(IConventionPropertyBuilder propertyBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnPropertyAddedNode.Run(ConventionDispatcher dispatcher)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.DelayedConventionScope.Run(ConventionDispatcher dispatcher)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Run()
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionBatch.Dispose()
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ImmediateConventionScope.OnModelInitialized(IConventionModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelInitialized(IConventionModelBuilder modelBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Internal.Model..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
   at Microsoft.EntityFrameworkCore.ModelBuilder..ctor(ConventionSet conventions, ModelDependencies modelDependencies, ModelConfiguration modelConfiguration)
   at Microsoft.EntityFrameworkCore.ModelConfigurationBuilder.CreateModelBuilder(ModelDependencies modelDependencies)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, ModelDependencies modelDependencies)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, ModelCreationDependencies modelCreationDependencies, Boolean designTime)
   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 factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSiteMain(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite callSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[[Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext, Microsoft.Extensions.DependencyInjection, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60],[System.Object, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]].VisitCallSite(ServiceCallSite callSite, RuntimeResolverContext argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeServiceProviderEngine.<>c__DisplayClass4_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[IDbContextDependencies](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_ContextServices()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
   at Microsoft.EntityFrameworkCore.Infrastructure.Internal.InfrastructureExtensions.GetService[IDatabaseFacadeDependencies](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[IDatabaseFacadeDependencies](IInfrastructure`1 accessor)
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_Dependencies()
   at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()
   at EFCore.MainPage.OnCounterClicked(Object sender, EventArgs e) in C:\Users\rober\source\repos\EFCore\EFCore\MainPage.xaml.cs:line 31
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.Controls.Internals.IButtonElement.PropagateUpClicked()
   at Microsoft.Maui.Controls.ButtonElement.ElementClicked(VisualElement visualElement, IButtonElement ButtonElementManager)
   at Microsoft.Maui.Controls.Button.SendClicked()
   at Microsoft.Maui.Controls.Button.Microsoft.Maui.IButton.Clicked()
   at Microsoft.Maui.Handlers.ButtonHandler.OnButtonTouchUpInside(Object sender, EventArgs e)
   at UIKit.UIControlEventProxy.Activated()
   at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass)
   at EFCore.Program.Main(String[] args) in C:\Users\rober\source\repos\EFCore\EFCore\Platforms\iOS\Program.cs:line 13
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)'
The app has been terminated.

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Thu, 22 Sep 2022 14:07:42 GMT

Hi @eerhardt !

I have done in different machine, the same error shows up!

@rolfbjarne
Copy link
Member Author

From @eerhardt on Thu, 22 Sep 2022 15:04:20 GMT

Are you able to get a binlog? See dotnet/efcore#28773 (comment)

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Sat, 24 Sep 2022 16:32:23 GMT

Hi @eerhardt binlog files are bellow:

binlog files.zip

@rolfbjarne
Copy link
Member Author

From @eerhardt on Mon, 26 Sep 2022 17:56:08 GMT

Hmm, unfortunately those logs don't contain much information. One thing I was able to confirm was that NullabilityInfoContextSupport was getting set to true. But I wasn't able to see any compiler or linker steps happen in the logs.

Did you delete the bin and obj folders to ensure everything is clean before capturing the logs?

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Mon, 26 Sep 2022 20:28:01 GMT

Hi @eerhardt

this binlog wore created after: delete the bin and obj folders to ensure everything is clean.
binlog.zip

the problem is when we have a string property on Model. if i remove this property everythings works see:

image

image

this error shows up only iOS.. Android and Windows, it's ok

@rolfbjarne
Copy link
Member Author

From @eerhardt on Mon, 26 Sep 2022 21:01:41 GMT

I don't see why NullabilityInfoContextSupport=true is not getting flown to the final app. Maybe there is something in the iOS tooling that doing this? @rolfbjarne do you have any ideas? In the attached binlogs, NullabilityInfoContextSupport is set to true. However, at runtime, the exception @RobertoGFilho is getting leads me to believe it is not being set to true:

[0:] An error occurred: 'NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.'. Callstack: '   at System.Reflection.NullabilityInfoContext.EnsureIsSupported()
   at System.Reflection.NullabilityInfoContext.Create(PropertyInfo propertyInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableConventionBase.IsNonNullableReferenceType(IConventionModelBuilder modelBuilder, MemberInfo memberInfo)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.Process(IConventionPropertyBuilder propertyBuilder)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.NonNullableReferencePropertyConvention.ProcessPropertyAdded(IConventionPropertyBuilder propertyBuilder, IConventionContext`1 context)

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Mon, 26 Sep 2022 21:15:58 GMT

@RobertoGFilho just in order to narrow things down: do you get the same behavior if you use Visual Studio for Mac (on the Mac)?

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Tue, 27 Sep 2022 11:54:09 GMT

hi @rolfbjarne !

I just work on Visual Studio for Windows!

image

i have shared this demo : https://github.com/RobertoGFilho/EFCore

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Tue, 27 Sep 2022 14:39:41 GMT

We set NullabilityInfoContextSupport to false by default:

<NullabilityInfoContextSupport Condition="'$(NullabilityInfoContextSupport)' == ''">false</NullabilityInfoContextSupport>

and the test project does not set NullabilityInfoContextSupport at all.

@RobertoGFilho can you try adding this to your project:

<PropertyGroup>
    <NullabilityInfoContextSupport>true</NullabilityInfoContextSupport>
</PropertyGroup>

and see if that works?

@rolfbjarne
Copy link
Member Author

From @eerhardt on Tue, 27 Sep 2022 14:55:55 GMT

@rolfbjarne - the Microsoft.EntityFrameworkCore NuGet package sets <NullabilityInfoContextSupport>true</NullabilityInfoContextSupport> in its buildTransitive folder. See dotnet/efcore#27474.

https://github.com/dotnet/efcore/blob/767bc93c6e6fca19868f486c7df8f4235bcf53cd/src/EFCore/buildTransitive/net6.0/Microsoft.EntityFrameworkCore.props#L3-L7

@rolfbjarne
Copy link
Member Author

From @RobertoGFilho on Tue, 27 Sep 2022 16:55:32 GMT

@rolfbjarne, @eerhardt i have already tryed , but it doesn't work

image

@rolfbjarne
Copy link
Member Author

From @rolfbjarne on Fri, 30 Sep 2022 13:34:12 GMT

The test project from the initial description works fine when I run it on a Mac.

The two binlogs (dotnet/efcore#28773 (comment), dotnet/efcore#28773 (comment)) come from a build that wasn't connected to the Mac, and thus only a very simple build was done.

@RobertoGFilho, please connect to a mac, build again and get the binlog, or try directly on the Mac (using Visual Studio for Mac) to see if that works for you.

@tj-devel709
Copy link
Contributor

I was able to reproduce the behavior that @RobertoGFilho is hitting. Building the provided sample on VS while remoting to my Mac causes the same exception to be thrown while deploying to a device (iPhone 12 running iOS 14.2.1) but does not throw on a simulator. Also, commenting out the string Name property on the Person Class causes the exception to not be thrown.

@tj-devel709 tj-devel709 added this to the Future milestone Oct 7, 2022
@tj-devel709 tj-devel709 added the bug If an issue is a bug or a pull request a bug fix label Oct 7, 2022
@tj-devel709
Copy link
Contributor

Here is the binlog from my build:
EFCore_Debug_AnyCPU_net6.0-ios_Build_2022-10-07T11_35_51.0318427-05_00.zip

@RobertoGFilho
Copy link

Hi @tj-devel709 ,you are correct. Thank you !

That's so important to convince my company migrate to MAUI with EFCore!

@schlaman
Copy link

schlaman commented Oct 24, 2022

Is there any more on this issue?? I have the EXACT same issue as it crashes when I have a string in the model.
The exception occurs in IOS only during EnsureCreatedAsync()


using System.ComponentModel.DataAnnotations.Schema;

namespace EFCoreTestDeploy.Data.Models;

[Table("vendor")]
public class Vendor
{
    public int VendorId { get; set; }

**// If this is remarked out then no exception**
    public string Description { get; set; }

    public int VendorCategoryPrimary { get; set; }
}

This is in a .NET MAUI test app with VS 17.4.0 Preview 4.
NET7.0
Windows 11.
Microsoft.EntityFrameworkCore.Sqlite v6.0.10 OR v7.0.0-rc.22472.11
In IOS only

@RobertoGFilho
Copy link

hi @tj-devel709 do you have idea when it will be fixed?
I've been workin a big project on MAUI and i need this resource working well.

@RobertoGFilho
Copy link

RobertoGFilho commented Nov 20, 2022

<!--DOESN'T WORKS on iOS-->
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.0" />

<!--WORKS-->
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.11" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="SQLitePCLRaw.core" Version="2.1.2" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.1.2" />
<PackageReference Include="SQLitePCLRaw.provider.dynamic_cdecl" Version="2.1.2" />
<PackageReference Include="SQLitePCLRaw.provider.sqlite3" Version="2.1.2" />
using Foundation;
using SQLitePCL;

namespace EFCore
{
    [Register("AppDelegate")]
    public class AppDelegate : MauiUIApplicationDelegate
    {
        protected override MauiApp CreateMauiApp()
        {
            //raw.SetProvider(new SQLite3Provider_sqlite3());
            return MauiProgram.CreateMauiApp();
        }
    }
}

references: https://vladislavantonyuk.azurewebsites.net/articles/Adding-SQLite-to-the-.NET-MAUI-application

@taublast
Copy link

taublast commented Jan 4, 2023

From @eerhardt on Thu, 18 Aug 2022 23:42:07 GMT

I don't believe this is a NullabilityInfoContextSupport issue. When I ran your app I see the following exception being thrown:

image

Have met this exception and worked around it inside .csproj:

	<!--IOS RELEASE-->
	<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net7.0-ios|AnyCPU'">
		<!--to be able to use some EF core methods-->
		<MtouchExtraArgs>--interpreter</MtouchExtraArgs>
		<UseInterpreter>True</UseInterpreter>
		<!--your codesign parameters will go below-->
	</PropertyGroup>

App has been approved and published to AppStore.

@schlaman
Copy link

schlaman commented Jan 16, 2023

using System.ComponentModel.DataAnnotations.Schema;

namespace EFCoreTestDeploy.Data.Models;

[Table("vendor")]
public class Vendor
{
public int VendorId { get; set; }

// If this is remarked out then no exception
public string Description { get; set; }

public int VendorCategoryPrimary { get; set; }
}

This is in a .NET MAUI test app with VS 17.5.0 Preview 2.
OR VS 17.4.3 Release
NET7.0
Windows 11.
Microsoft.EntityFrameworkCore.Sqlite v6.0.10 OR v7.0.0-rc.22472.11 or v7.0.2
In IOS only!!!

I STILL have the following error!!

" NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.
[0:] An error occurred: 'NullabilityInfoContext is not supported in the current application because 'System.Reflection.NullabilityInfoContext.IsSupported' is set to false. Set the MSBuild Property 'NullabilityInfoContextSupport' to true in order to enable it.'. Callstack: ' at System.Reflection.NullabilityInfoContext.EnsureIsSupported()
"

As suggested earlier I do have the following in the project file:

	<PropertyGroup>
		<NullabilityInfoContextSupport>true</NullabilityInfoContextSupport>
		<Nullable>enable</Nullable>
	</PropertyGroup>

Can someone please help with resolving this. It is a very simple use case. When EnsureCreated() is called then the error happens as described above in my previous post and of the earlier post where remarking out the "Description" string of the 'Vendor' Class and that makes this work. If the Model Class (Vendor in this case) has ANY string properties then the exception occurs upon doing the EnsureCreated() call. Otherwise if you have a Table model without any string properties then everything works perfectly.

At this point it feels impossible to continue with App development on IOS until this is resolved!!

Thanks,
Craig

@rolfbjarne rolfbjarne modified the milestones: Future, .NET 8 Jan 16, 2023
@schlaman
Copy link

schlaman commented Jan 18, 2023

I have added a minimal GitHub project that illustrates the 'NullabilityInfoContext' issue with EnsureCreated() on a Physical IOS device only with EF Core and .NET Maui.

GitHub EF Core demo project

@rolfbjarne
Copy link
Member Author

@schlaman can you try your sample from the Mac directly using VS for Mac and see if that works?

@schlaman
Copy link

schlaman commented Jan 18, 2023

@rolfbjarne First of all thank you so much for your response!! I'm feeling very discouraged by this problem I've had for a long time now.

I haven't been developing for the Mac but I can get the latest Visual Studio installed on my Mac and give it a try.

**Also, one other note is that this doesn't always fail. Just virtually always with brief intermittent times of working when some kind of change is made (like the DB filename) ** Last night I was playing with adding in some of the other related NuGet packages that had been mentioned elsewhere as maybe solving the problem and then it worked. But I tried to repro by taking those back out and then it didn't work but then when I added the extra NuGets back in it still didn't work again. I couldn't make it work at all then.

I then tried renaming the database Sqlite DB file I was creating and then ran it and it worked just fine. I then changed the name back and it stopped working. Then I changed the name back again to the new name and then it didn't work. I could not make it work from there.
I also have been deleting the app off the device when I deploy (some of the time - I've tried different combinations). It seems impossible to get an exact repro scenario. But I bet if people play a bit they can get it to fail and then will have a hard time getting it to work again.

I don't know if I should have Nullability turned on and if so what I should be doing with the attributes for the Table model's string properties 'Vendor.Description' in this case. Is that somehow related to this issue?

@rolfbjarne rolfbjarne added the need-attention An issue requires our attention/response label Jan 19, 2023
@schlaman
Copy link

I am working on getting my mac setup to test this. Just figuring out certificates and such on it now.
I have never built/deployed on the mac before.

Is there anything else I can do to test this. I'm still working on getting the answer for the mac but this is a big time consumer for me to do that!

@rolfbjarne
Copy link
Member Author

I believe I figured out the problem, and it only happens when using Hot Restart from Windows.

The underlying cause is that when using Hot Restart, the NullabilityContextInfoSupported MSBuild property isn't properly propagated to the app at runtime. I'm not entirely sure why this happens, but the runtimeconfig.bin file in the app says that "System.Reflection.NullabilityInfoContext.IsSupported=false" (while the one produced during the build says the opposite). I'm guessing that we're copying the runtimeconfig.bin file from the prebuilt app instead of using the one produced during the build.

The workaround seems to be to force the runtime setting for NullabilityContextInfoSupported by executing this early on in the process startup (I added it as the first line of the MauiProgram.CreateMauiApp:

AppContext.SetSwitch("System.Reflection.NullabilityInfoContext.IsSupported", true);

and now the test project seems to work fine.

@rolfbjarne rolfbjarne removed the need-attention An issue requires our attention/response label Jan 23, 2023
@rolfbjarne
Copy link
Member Author

This is an issue in VS for Windows, so I've filed https://developercommunity.visualstudio.com/t/For-iOS-builds-runtimeconfigbin-isnt-b/10259889?port=1025&fsid=26f22907-18bf-4765-9f85-d2c2569fd3aa with a simpler test case.

Please vote/comment on that issue instead of this one for any questions or concerns.

@rolfbjarne rolfbjarne closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2023
@schlaman
Copy link

Thank you @rolfbjarne !!

I GREATLY appreciate you looking into this and solving this issue!!
I verified that the simple workaround works.

You were guessing that perhaps the runtimeconfig.bin file was being copied from the prebuilt app instead of using the one produced during the build. If that is the case, are there further implications of other MSBuild properties being lost?
Is there something else to watch out for?
Hopefully the fix makes it into VS quickly.

Thanks again!

@rolfbjarne
Copy link
Member Author

If that is the case, are there further implications of other MSBuild properties being lost?

Yes, there are a few others, but it's rare to change the default for most of these for mobile projects: https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md

@eerhardt
Copy link
Contributor

but it's rare to change the default for most of these for mobile projects

Just an FYI. The NullabilityInfoContext was explicitly designed to be changed depending on the need. By default, this nullability info isn't needed in an app. So we trim it in order to make the app smaller. But some libraries really do need this info (EF.Core in this example). So when using EF.Core in an app will change the default so the information is preserved.

Hopefully VS fixes this issue generally.

@schlaman
Copy link

@rolfbjarne , @eerhardt
Thanks to both of you for explaining that further!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
None yet
Development

No branches or pull requests

6 participants