Running PMC commands with the 2.1 nightlies has a binding redirect error:
Forcing a lower System.ComponentModel.Annotations and ignoring the nuget warnings makes it work.
PM> update-database
System.IO.FileLoadException: Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.CoreConventionSetBuilder.CreateConventionSet()
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateConventionSet(IConventionSetBuilder conventionSetBuilder)
at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
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.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
PM>
Include a complete code listing (or project/solution) that we can run to reproduce the issue.
Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<!-- uncommenting this, makes it work -->
<!--<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0">
<NoWarn>NU1605</NoWarn>
</PackageReference>-->
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.0-preview1-27959">
<NoWarn>NU1605</NoWarn>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.0-preview1-27959" PrivateAssets="true">
<NoWarn>NU1605</NoWarn>
</PackageReference>
</ItemGroup>
</Project>
EF Core version: 2.1 nightlies
Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system:
IDE: Visual Studio 2017 15.6 preview1
What error do you get without <NoWarn>NU1605</NoWarn>
?
@bricelam
"myproject.csproj" (Restore target) (1) ->
(Restore target) ->
myproject.csproj : error NU1605: Detected package downgrade: System.ComponentModel.Annotations from 4.5.0-preview1-26016-05 to 4.4.0. Reference the package directly from the project to select a different version.
myproject.csproj : error NU1605: myproject -> Microsoft.EntityFrameworkCore.SqlServer 2.1.0-preview1-27959 -> Microsoft.EntityFrameworkCore.Relational 2.1.0-preview1-27959 -> Microsoft.EntityFrameworkCore 2.1.0-preview1-27959 -> System.ComponentModel.Annotations (>= 4.5.0-preview1-26016-05)
myproject.csproj : error NU1605: myproject -> System.ComponentModel.Annotations (>= 4.4.0)
myproject.csproj : error NU1605: Detected package downgrade: System.ComponentModel.Annotations from 4.5.0-preview1-26016-05 to 4.4.0. Reference the package directly from the project to select a different version.
myproject.csproj : error NU1605: myproject -> Microsoft.EntityFrameworkCore.Tools 2.1.0-preview1-27959 -> Microsoft.EntityFrameworkCore.Design 2.1.0-preview1-27959 -> Microsoft.EntityFrameworkCore.Relational 2.1.0-preview1-27959 -> Microsoft.EntityFrameworkCore 2.1.0-preview1-27959 -> System.ComponentModel.Annotations (>= 4.5.0-preview1-26016-05)
myproject.csproj : error NU1605: myproject -> System.ComponentModel.Annotations (>= 4.4.0)
Hmm, I think I'm going to need your full project to dig into this one...
@bricelam Here is a repro: https://github.com/BradBarnich/EF21-tools-repro
It's just a 4.6.1 class library, adding EF Tools and SqlServer, then try to run a PMC command...
Looks like .NET Framework class libraries are a bit crippled on 2.1. To workaround the issue, you can add the following to your *.csproj
.
<PropertyGroup>
<AutoGenerateBindingRedirects>True</AutoGenerateBindingRedirects>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
This might go away when the version of MSBuild that ships inside Visual Studio gets updated...
@bradwilson @onovotny Have you hit any similar problems from not having binding redirects on .NET Framework Class Libraries?
I have not heard any complaints yet. I'm not using 2.1, personally. Also, we do emit those values for you:
https://github.com/xunit/xunit/blob/master/src/xunit.core/build/xunit.core.targets
Ha, nice. That's the solution I'm leaning towards. We also already do <GenerateRuntimeConfigurationFiles>
on .NET Core.
ah right, thanks. Works great now
I am having this issue and none of the suggested workarounds work for me. I am dead in the water. Everything was working fine for me until I stupidly decided to update nuget packages. I feel like I am back in DLL Hell.
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Source=Microsoft.EntityFrameworkCore
@camainc Can you post your full csproj?
Actually I eventually worked through this after spending a couple of hours on Google and StackOverflow.
I had to add the following to my web.config:
<dependentAssembly>
<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0" />
</dependentAssembly>
The key was figuring out the correct version number for the newVersion attribute.
This is a fairly common issue I have run into several instances of this because with ProjectReference nuget packages showing in the references you see the nuget package version and not the assembly version for binding redirects and the auto redirects do not seem to function.
Thanks camainc for pointing out the correct version for this assembly.
Most helpful comment
Actually I eventually worked through this after spending a couple of hours on Google and StackOverflow.
I had to add the following to my web.config:
The key was figuring out the correct version number for the newVersion attribute.