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 #28773

Closed
RobertoGFilho opened this issue Aug 18, 2022 · 36 comments
Closed

Microsoft.EntityFrameworkCore.Sqlite 7 crash on iOS #28773

RobertoGFilho opened this issue Aug 18, 2022 · 36 comments

Comments

@RobertoGFilho
Copy link

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"

@eerhardt
Copy link
Member

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

image

@RobertoGFilho
Copy link
Author

@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?

@eerhardt
Copy link
Member

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.

@RobertoGFilho
Copy link
Author

@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

@eerhardt
Copy link
Member

What is the output of dotnet workload list?

@RobertoGFilho
Copy link
Author

RobertoGFilho commented Aug 19, 2022

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.

@eerhardt
Copy link
Member

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

@eerhardt
Copy link
Member

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

@RobertoGFilho
Copy link
Author

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

@RobertoGFilho
Copy link
Author

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

@eerhardt
Copy link
Member

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.

@eerhardt
Copy link
Member

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.

@RobertoGFilho
Copy link
Author

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

@eerhardt
Copy link
Member

eerhardt commented Sep 6, 2022

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

@RobertoGFilho
Copy link
Author

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; }
}

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 11, 2022

What is ObservableObject?

@RobertoGFilho
Copy link
Author

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

@RobertoGFilho
Copy link
Author

RobertoGFilho commented Sep 12, 2022

[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.

@RobertoGFilho
Copy link
Author

Hi @eerhardt !

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

@eerhardt
Copy link
Member

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

@RobertoGFilho
Copy link
Author

Hi @eerhardt binlog files are bellow:

binlog files.zip

@eerhardt
Copy link
Member

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?

@RobertoGFilho
Copy link
Author

RobertoGFilho commented Sep 26, 2022

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

@eerhardt
Copy link
Member

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

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

@RobertoGFilho
Copy link
Author

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

We set NullabilityInfoContextSupport to false by default:

https://github.com/xamarin/xamarin-macios/blob/b6cdde42807c6ed5c5fedf471feea0ce4441e584/dotnet/targets/Xamarin.Shared.Sdk.targets#L135

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?

@eerhardt
Copy link
Member

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

<!--
MAUI (and other size-conscient profiles) trim the nullability attributes, causing the EF Core NRT support to break.
This prevents the attributes from being trimmed.
-->
<NullabilityInfoContextSupport>true</NullabilityInfoContextSupport>

@RobertoGFilho
Copy link
Author

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

image

@rolfbjarne
Copy link
Member

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

The two binlogs (#28773 (comment), #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.

@RobertoGFilho
Copy link
Author

hi @rolfbjarne @eerhardt binlogs connected to a mac: binlog.zip

@rolfbjarne
Copy link
Member

@RobertoGFilho
Copy link
Author

RobertoGFilho commented Oct 3, 2022

@rolfbjarne, @ajcvickers @ErikEJ @jsuarezruiz @eerhardt @Eilon @mattleibow i connected to a MAC, but my envioment doesn't use MAC to build a app. See:

My Envioroment:

  • Windows 11;
  • Visual Studio 2022 for Windows 11;
  • Devices : Iphone 7 Plus and Iphone 6 plus;

Thecnologies:

  • Hot Restart;
  • Hot Reload;

I understand that you test on MAC is ok, But the problem here is working on Windows without a MAC. I've been working this way with Xamarin Forms and EF Core 3.1 without problem. But when i started working MAUI and EF 7.xx i not able to work on iOS, because string property on model trigger this error.

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

On Android and Windows works perfectly.

Conclusion
We need to fix this on Windows environment, because will impact many developers that want to work with MAUI and EF 7.xxx.

@rolfbjarne
Copy link
Member

This is unlikely to be a problem in EFCore if it only occurs in certain build environments, so I'm moving this issue.

@rolfbjarne
Copy link
Member

This issue was moved to xamarin/xamarin-macios#16228

@roji roji closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2022
@taublast
Copy link

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

image

this is can be worked around this way: https://stackoverflow.com/a/74786481/7149454

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants