Efcore: {"Could not load type 'System.Diagnostics.CodeAnalysis.MaybeNullAttribute' from assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.":"System.Diagnostics.CodeAnalysis.MaybeNullAttribute"}

Created on 24 Sep 2019  路  21Comments  路  Source: dotnet/efcore

After getting today's release of .net core 3.0.
I have upgraded to EF core 3.0 library and we have started seeing this error

System.TypeLoadException: Could not load type 'System.Diagnostics.CodeAnalysis.MaybeNullAttribute' from assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
   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.RunVisitor.VisitOnPropertyAdded(OnPropertyAddedNode node)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnPropertyAddedNode.Accept(ConventionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.Visit(ConventionNode node)
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.ConventionVisitor.VisitConventionScope(ConventionScope node)
   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)
   at Microsoft.EntityFrameworkCore.ModelBuilder..ctor(ConventionSet conventions)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.<GetModel>b__1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at System.Lazy`1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor)
   at System.Lazy`1.CreateValue()
   at System.Lazy`1.get_Value()
   at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder)
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_3(IServiceProvider p)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache(ServiceCallSite callSite, RuntimeResolverContext context, ServiceProviderEngineScope serviceProviderEngine, RuntimeResolverLock lockType)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScopeCache(ServiceCallSite singletonCallSite, RuntimeResolverContext context)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.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[T](IServiceProvider provider)
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
   at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
   at Microsoft.EntityFrameworkCore.DbContext.get_Model()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityType()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.CheckState()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.get_EntityQueryable()
   at Microsoft.EntityFrameworkCore.Internal.InternalDbSet`1.System.Linq.IQueryable.get_Provider()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, LambdaExpression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)
   at Microsoft.Education.AristoServices.ConnectorApp.Connectors.StateManagement.DbWorkflowExecutionStateManager.GetExecutionDetails(String executionId) in D:\code\AristoServices\src\ConnectorApp\Connectors\StateManagement\DbWorkflowExecutionStateManager.cs:line 35
   at Microsoft.Education.AristoServices.ConnectorApp.Connectors.StateManagement.DbWorkflowExecutionStateManager.UpdateExecutionStatusAsync(String executionId, WorkflowExecutionStatus executionStatus) in D:\code\AristoServices\src\ConnectorApp\Connectors\StateManagement\DbWorkflowExecutionStateManager.cs:line 92
   at Microsoft.Education.AristoServices.ConnectorApp.Web.Services.ConnectorWorkerQueueClient.SendMessageAsync(ConnectorWorkerMessage message) in D:\code\AristoServices\src\ConnectorApp\ConnectorApp.Web\Services\ConnectorWorkerQueueClient.cs:line 65
   at Microsoft.Education.AristoServices.ConnectorApp.Web.Services.ConnectorWorkerQueueClient.QueueWorkAsync[TRequestParameters](ConnectorWorkRequest`1 workRequest, String connectorType) in D:\code\AristoServices\src\ConnectorApp\ConnectorApp.Web\Services\ConnectorWorkerQueueClient.cs:line 46
   at Microsoft.Education.AristoServices.ConnectorApp.Web.Controllers.RequestController`1.QueueWork(ConnectorWorkRequest`1 payload) in D:\code\AristoServices\src\ConnectorApp\ConnectorApp.Web\Controllers\RequestController.cs:line 50
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at NSwag.AspNetCore.Middlewares.SwaggerUiIndexMiddleware.Invoke(HttpContext context)
   at NSwag.AspNetCore.Middlewares.RedirectToIndexMiddleware.Invoke(HttpContext context)
   at NSwag.AspNetCore.Middlewares.OpenApiDocumentMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
closed-external customer-reported

Most helpful comment

@AndriySvyryd
You are mixing Xamarin.Android SDK with the Target Android SDK. You can have Xamarin.Android 10 and still target 9 or lower. And still, the issue occurs even with Xamarin.Android 10 and targeting Android Q.

@smitpatel
I will report the Android and iOS issues on the corresponding projects.

All 21 comments

@sunildixit - This error occurred when using preview SDK of .NET Core. Can you make sure that you have uninstalled all 3.0 preview SDKs and install 3.0 RTM SDK released today?

You are actually right. I just thought, that when the VS got upgraded it would've have removed the preview, which it didn't. After uninstalling it, it has started working. Thank you for your help.

Actually, I am using the latest stable version - 3.0.100. I haven't pre-installed any of the preview versions, and I am still getting this exception in my Xamarin projects.

Visual Studio 2019 version 16.3

Package versions:
Microsoft.EntityFrameworkCore (Sqlite & Design & Tools) - 3.0.0
SQLitePCLRaw.bundle_e_sqlite3 - 2.0.1

dotnet --info output
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33

.NET Core SDKs installed:
3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@smitpatel

@mduchev - Can you share a repro project? It may have something to do with being a Xamarin project. If we get a repro, we can isolate where is the issue and pass on to appropriate team.

Why is this issue closed? Im also getting this error after upgrading from preview 7 to public release - 3.0.100

Hey all, I resolved mine the following way :

  • Make sure all .net core runtimes and SDKs are uninstalled. Run dotnet --info to see. If installing 3.0.100 didnt remove the previews, go to those dirs and manually remove them. Re install (modify) the net core 3.0.100 installation to be safe again.

  • Make sure you have installed VS 2019 16.3.1

Error should disappear.

@smitpatel I will try to find the time to create a repro.

@R00iBaard I have never installed any preview versions, nor do I have anything else than 3.0.100 on my device. You can see my device --info in my previous comment. This is not a solution, obviously. There is still an issue!

@mduchev same situation here. I notice that Visual Studio 16.3.1 is shipped with an "embedded" version of net core 3, which differ from a standalone installation of netcore 3 sdk.
image

I solved by downgrading to efcore 2.6, I think there are some issue with netstandard 2.1 https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-3-0-preview-8-and-entity-framework-6-3-preview-8/

The project is based on xamarin and it runs on net standard 2.1

@smitpatel Here you are a sample project.
TestEFC3XamarinApp.zip

Steps to reproduce:
1) Run the app
2) Click on the button.
3) When the button is clicked, we are creating a new entity of type Address.
4) After the entity is created, we are adding it to Addresses DbSet (here is where the issue occurs)
5) Before we are able to call SaveChangesAsync, the app crashes with the same exception:

_System.TypeLoadException
Message=Could not resolve type with token 01000143 from typeref (expected class 'System.Diagnostics.CodeAnalysis.MaybeNullAttribute' in assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51')_

NOTE: This is tested on Android project only. The iOS project has other issues - it can't be run on simulator, nor on a real device. There I am getting these errors:
ios_simulator_errors.txt
ios_device_errors.txt

I don't know if I these are reported already, or should I open new issues.

I solved by downgrading to efcore 2.6, I think there are some issue with netstandard 2.1 https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-3-0-preview-8-and-entity-framework-6-3-preview-8/

The project is based on xamarin and it runs on net standard 2.1

@cagianx Yes, the configuration works with no issues running EFCore 2.2.6. Either there are some issues for EFCore 3.0, or there is new configuration that we need to apply.

@mduchev - Thanks for the code. I will investigate.

Same thing with Xamarin.Android.
Is the netstandard.ddl, when using Android from the net core sdk or is it supplied by Xamarin.Android?
If it is the latter, I think we just need a later netstandard.dll for Xamarin.Android (to make Android work)
I need some fixes of the 3.0.0 version so downgrading is not an option for me :(

@mduchev @groege
After going through all the comments, I am not able to test out things as my dev environment is not setup for Xamarin project. I fairly believe that this is issue with netstandard2.1 and Xamarin projects. Hence I would recommend you guys to file an issue on their repo https://github.com/xamarin/xamarin-android/issues

They would be best to help you out.

@cagianx - Regarding multiple different SDK installed for 3.0, please file an issue at https://github.com/dotnet/core-sdk/issues

Closing this as external. EF is using netstandard2.1 API. Issues like this are likely caused by SDK or project type is not supported properly on netstandard2.1 RTM.

You need to target at least Xamarin.Android __10.0__ or Xamarin.Mac __5.16__ to use netstandard2.1 and EF Core 3.0.0
https://github.com/dotnet/standard/blob/master/docs/versions.md

@AndriySvyryd I'm targetting those versions and still getting the error

Sadly I've been using the latest versions of Visual Studio (prerelease and non prerelease)
Latest Version of VS2019 is using Xamarin.Android 10.0 and the latest prerelease is using 10.1...
Both have the same issue, I think we'll need another Xamarin.Android version with a proper dll...

@shaks786 @groege Check that the .csproj is actually targeting 10.0 as the minimum version, if so please open an issue containing a small repro project on https://github.com/xamarin/xamarin-android/issues and link here.

@AndriySvyryd Are you talking about the API Level? If so, are you saying NetStandard 2.1 is only compatible with Android Q?
So not even Android Pie works? That would be disastrous... and I'm sure I'm not alone in saying it is really important to work with older versions as well...
I've set target Version to 10 (API 29 - Q); minimum version to 6 (API 23 - Marshmallow)
Latest Visual Studio pre release version, which is using Xamarin.Android 10.1 and also the normal version which is using Xamarin.Android 10.

@AndriySvyryd
You are mixing Xamarin.Android SDK with the Target Android SDK. You can have Xamarin.Android 10 and still target 9 or lower. And still, the issue occurs even with Xamarin.Android 10 and targeting Android Q.

@smitpatel
I will report the Android and iOS issues on the corresponding projects.

Was this page helpful?
0 / 5 - 0 ratings