Efcore: Could not load file or assembly System.ComponentModel.Annotations, Version=4.2.0.0

Created on 9 Sep 2018  ·  105Comments  ·  Source: dotnet/efcore

Hi

the past few days I tried to get out of "DLL hell 2.0" aka nuget packages :-)
I setup my whole solution on VS in a brand new directory, created each project as a new one and only tool the sources over.
Doing this I also updated alle the nuget packages to the latest version.
Running the app it hits an exception when doing "Database.Migrate()"

I tried every workaround I found in the web. Adding binding redirect in the csproj, manually settings the version numbers in the app.config, downgrading everything to the latest stable (hitting another exception (System.Interactive.Async Version=3.0.3000.0 - also well documented and for me unresolvable)

My current state is nuget packages as described below and hitting the Annotation version conflict.

I hope one of the knowing developers can hint me how to fix that issue. (am I the only one? if not, why do the devs getting the same exception not document hoe to work around while not the nuget "fire and forget" mentality works?)

so any advice is welcome :-)

Exception message:
Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

Further technical details

EF Core version: 2.2.0-preview1-35029
Database Provider: SQLite provider
Operating system: Win10
IDE: VS 15.8.3

closed-external customer-reported

Most helpful comment

In some form this problem is already there for more then two years. In my experience it only shows up in rather complex solutions were both .Net Core (EF Core) and traditional .Net Frameworks (both 4.6.1 and 4.7.2) are used. Since the introduction of .Net Core 2.1 the problem can nearly always be solved by manually editing your config file in one or more projects (app.config in my case). Include the lines below in the runtime section.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
  <dependentAssembly>
     <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

All 105 comments

@obelixA Can you post the csproj file?

``




Debug
AnyCPU
{7172124B-88FE-4C27-952A-3BDF205E1BCE}
Library
Properties
ActiveCashSystem
DataReaderWriterSQLITE
v4.6.1
512
true




true
full
false
bin\Debug\
DEBUG;TRACE
prompt
4
x86


pdbonly
true
bin\Release\
TRACE
prompt
4
x86



....\packages\Microsoft.Data.Sqlite.Core.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Data.Sqlite.dll


....\packages\Microsoft.EntityFrameworkCore.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.EntityFrameworkCore.dll


....\packages\Microsoft.EntityFrameworkCore.Abstractions.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Abstractions.dll


....\packages\Microsoft.EntityFrameworkCore.Relational.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Relational.dll


....\packages\Microsoft.EntityFrameworkCore.Sqlite.Core.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.EntityFrameworkCore.Sqlite.dll


....\packages\Microsoft.Extensions.Caching.Abstractions.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Caching.Abstractions.dll


....\packages\Microsoft.Extensions.Caching.Memory.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Caching.Memory.dll


....\packages\Microsoft.Extensions.Configuration.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll


....\packages\Microsoft.Extensions.Configuration.Abstractions.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll


....\packages\Microsoft.Extensions.Configuration.Binder.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Configuration.Binder.dll


....\packages\Microsoft.Extensions.DependencyInjection.2.2.0-preview1-35029\lib\net461\Microsoft.Extensions.DependencyInjection.dll


....\packages\Microsoft.Extensions.DependencyInjection.Abstractions.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll


....\packages\Microsoft.Extensions.Logging.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Logging.dll


....\packages\Microsoft.Extensions.Logging.Abstractions.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Logging.Abstractions.dll


....\packages\Microsoft.Extensions.Options.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Options.dll


....\packages\Microsoft.Extensions.Primitives.2.2.0-preview1-35029\lib\netstandard2.0\Microsoft.Extensions.Primitives.dll


....\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll
True
True


....\packages\Remotion.Linq.2.2.0\lib\net45\Remotion.Linq.dll


....\packages\SQLitePCL.raw.0.9.4-pre1\lib\net45\SQLitePCL.raw.dll


....\packages\SQLitePCLRaw.bundle_e_sqlite3.1.1.11\lib\net45\SQLitePCLRaw.batteries_e_sqlite3.dll


....\packages\SQLitePCLRaw.bundle_green.1.1.11\lib\net45\SQLitePCLRaw.batteries_green.dll


....\packages\SQLitePCLRaw.bundle_green.1.1.11\lib\net45\SQLitePCLRaw.batteries_v2.dll


....\packages\SQLitePCLRaw.core.1.1.11\lib\net45\SQLitePCLRaw.core.dll


....\packages\SQLitePCLRaw.provider.e_sqlite3.net45.1.1.11\lib\net45\SQLitePCLRaw.provider.e_sqlite3.dll



....\packages\System.AppContext.4.3.0\lib\net46\System.AppContext.dll
True
True


....\packages\System.Buffers.4.5.0\lib\netstandard2.0\System.Buffers.dll


....\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll


....\packages\System.ComponentModel.Annotations.4.5.0\lib\net461\System.ComponentModel.Annotations.dll




....\packages\System.Console.4.3.1\lib\net46\System.Console.dll
True
True



....\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll


....\packages\System.Globalization.Calendars.4.3.0\lib\net46\System.Globalization.Calendars.dll
True
True


....\packages\System.Interactive.Async.3.2.0\lib\net46\System.Interactive.Async.dll


....\packages\System.IO.Compression.4.3.0\lib\net46\System.IO.Compression.dll
True
True



....\packages\System.IO.Compression.ZipFile.4.3.0\lib\net46\System.IO.Compression.ZipFile.dll
True
True


....\packages\System.IO.FileSystem.4.3.0\lib\net46\System.IO.FileSystem.dll
True
True


....\packages\System.IO.FileSystem.Primitives.4.3.0\lib\net46\System.IO.FileSystem.Primitives.dll
True
True


....\packages\System.Memory.4.5.1\lib\netstandard2.0\System.Memory.dll


....\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll
True
True


....\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll
True
True



....\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll


....\packages\System.Runtime.CompilerServices.Unsafe.4.5.1\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll


....\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll
True
True


....\packages\System.Security.Cryptography.Algorithms.4.3.1\lib\net461\System.Security.Cryptography.Algorithms.dll
True
True


....\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll
True
True


....\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll
True
True


....\packages\System.Security.Cryptography.X509Certificates.4.3.2\lib\net461\System.Security.Cryptography.X509Certificates.dll
True
True








....\packages\System.Xml.ReaderWriter.4.3.1\lib\net46\System.Xml.ReaderWriter.dll
True
True


....\packages\TracerX-Logger.6.1\lib\TracerX-Logger.dll














20170319165849_acsFactura_Initial.cs




20170202104951_MyFirstMigration.cs



20170202153856_KundenInfo_Notiz.cs



20170212084627_Gutscheine.cs



20170212185540_GS_Rabatte.cs



20170310220932_OLVState.cs



20170320160500_Telefonnummernsuche.cs



20170330191444_AZE_first.cs



20170416100055_Reservierungen_first.cs



20170818142254_KassenbuchBestand.cs



20171013065055_B2O_first.cs



20171125152800_GS_PartnerLokal.cs



20171126083828_GS_PartnerLokalListe.cs



20171219145725_Preisebenen.cs



20180523070725_Mappings.cs



20180524145249_Kostenstellen.cs



20180626081145_GemerkteWerte.cs




20170310080312_Help_Initial.cs




20170722191556_Logging_initial.cs










{1c69894c-51fe-4f05-be9d-47db1bfb8341}
Manager


{817c75e9-836f-4c37-bd85-d694a897a7f1}
Types




copy *.dll $(SolutionDir)\$(OutDir)
copy *.PDB $(SolutionDir)\$(OutDir)





This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.










`

@obelixA The problem may be related to binding re-directs not being added for class library projects. There is apparently an "Add-BindingRedirect" command that might help, but the general consensus on the team is that getting this to work with old-style "packages.config" NuGet will be hard and the best bet for success is to switch over to using "package references". There is a way to migrate or just switch on package references in NuGet config and create the project again.

@ajcvickers First of all: thanks for your help!
My first try was to only convert the trouble making project. NOPE, does not work.
Than I converted all 84 projects in the solution. Clean, rebuild and... NOPE, doesn't work either.
So by now I have a top modern solution with some 100k lines of code that can compile perfectly (ok nearly perfectly, some warnings left) but cannot be executed..,
Do you have an idea what I could do else?
thanks in advance!

@obelixA When you say, "doesn't work" do you mean it still gives the same error?

yes. same error...

DBReaderWriter : Die Datei oder Assembly "System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)

@obelixA Unfortunately we're out of ideas to try. Would it be possible to post a project/solution that reproduces what you are seeing so that we can investigate?

Would a remote session be ok? There are so many libraries involved that I'm not sure I can create a test project that reflects the circumstances...
If so, drop me a message at a dot bohmann at acs-it-systems dot de

@obelixA Unfortunately this isn't something we will be able to do. If you have a support contract with Microsoft, then you might want to follow up through that channel.

ok, so i'll do my very best to create a project reflecting the issue...

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

I'll do my very best to provide the project, but I am ill and bound to bed since several days and will have to stay afk for some more days :-( sorry for that delay, but I will come around with a project for sure when again fit for work...

I get the same exception on a .NET Framework 4.7.2 project with xunit, and setting xunit.runner.json appDomain to denied

sample project: https://github.com/gojanpaolo/ef-13268

@gojanpaolo Thanks!

@karelz @danmosemsft @natemcmaster The sample project in the comment is very minimal and reproduces the issue. I have spent a couple of hours investigating without luck and there is nothing specific to EF in this other than the combination of packages. So my guess is that this is an issue with:

  • The shipped packages--either ones we build or ones corefx builds
  • Something going wrong with MSBuild
  • Runtime assembly resolution

Ideas on who/where to continue the investigation?

@gojanpaolo which xunit runner are you using? I tried your repro in VS and didn't get an error.

image

@natemcmaster I am using the VS runner. Let me try again and let you know the results.

@natemcmaster I just tried the sample project as it is and I get the exception. I use VS 15.7.2 and Win7.
image

I used VS 15.9 Preview on Windows 10. I wonder if this could have anything to do with the version of .NET Framework or Visual Studio. I’m not the right person to investigate this further unfortunately. @ajcvickers you might try forwarding this to the VS Test or .NET Framework teams internally.

@natemcmaster It repros for me 100% in the VS test runner with the latest 15.8 on Win10. I'll try 15.9 tomorrow.

@gojanpaolo Please try to update your .NET Framework version to 4.7.1 or later

@ErikEJ I checked the .NET framework version on my machine and it seems to be 4.7.2 (Release is 461814).

image

@ErikEJ I also have 4.7.2 on the machine where this fails.

So it turns out I was actually using the R# test runner out of habit, rather than the VS runner. With the VS runner the test passes for me on two different machines, both of which don't work with the R# test runner. So this means I'm now back to not being able to reproduce what @gojanpaolo is seeing.

@gojanpaolo Can you post the text from the Output window. On my machine where it works I see:

[9/26/2018 9:22:51 AM Informational] ------ Run test started ------
[9/26/2018 9:22:53 AM Informational] [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.0 (32-bit Desktop .NET 4.0.30319.42000)
[9/26/2018 9:22:54 AM Informational] [xUnit.net 00:00:00.69]   Discovering: net_472
[9/26/2018 9:22:54 AM Informational] [xUnit.net 00:00:00.75]   Discovered:  net_472
[9/26/2018 9:22:54 AM Informational] [xUnit.net 00:00:00.75]   Starting:    net_472
[9/26/2018 9:22:54 AM Informational] [xUnit.net 00:00:01.20]   Finished:    net_472
[9/26/2018 9:22:55 AM Informational] ========== Run test finished: 1 run (0:00:03.2705114) ==========

@ajcvickers Please see output text. Should I try updating VS to 15.8 (currently using 15.7.4)?

[9/26/2018 11:34:56 AM Informational] ------ Run test started ------
[9/26/2018 11:34:57 AM Error] An exception occurred while invoking executor 'executor://xunit/VsTestRunner2/uap': Could not find Windows Runtime type 'Windows.ApplicationModel.Package'.
Operation is not supported on this platform.
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.4.0 (32-bit Desktop .NET 4.0.30319.42000)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.14]   Discovering: net_472
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.18]   Discovered:  net_472
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.19]   Starting:    net_472
[9/26/2018 11:34:57 AM Error] [xUnit.net 00:00:00.44]     net_472.Tests.Test [FAIL]
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]       System.IO.FileNotFoundException : Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]       Stack Trace:
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.CoreConventionSetBuilder.CreateConventionSet()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateConventionSet(IConventionSetBuilder conventionSetBuilder)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass5_0.<GetModel>b__1()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at System.Lazy`1.CreateValue()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at System.Lazy`1.LazyInitValue()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at System.Lazy`1.get_Value()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServicesBuilder.<>c.<TryAddCoreServices>b__7_1(IServiceProvider p)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactory(FactoryCallSite factoryCallSite, ServiceProviderEngineScope scope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProviderEngineScope scope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProviderEngineScope scope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine.<>c__DisplayClass1_0.<RealizeService>b__0(ServiceProviderEngineScope scope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.GetService(Type serviceType)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.DbContext.get_DbContextDependencies()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.DbContext.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.Microsoft.EntityFrameworkCore.Infrastructure.IInfrastructure<System.IServiceProvider>.get_Instance()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Internal.InternalAccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure`1 accessor)
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.get_DatabaseCreator()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]            at Microsoft.EntityFrameworkCore.Infrastructure.DatabaseFacade.EnsureCreated()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.44]         net_472\Tests.cs(17,0): at net_472.Tests.Test()
[9/26/2018 11:34:57 AM Informational] [xUnit.net 00:00:00.45]   Finished:    net_472
[9/26/2018 11:34:58 AM Informational] ========== Run test finished: 1 run (0:00:01.254) ==========

@gojanpaolo Worth trying.

@natemcmaster @danmosemsft The version of the "System.ComponentModel.Annotations" package we are building against is 4.5.0: https://github.com/aspnet/EntityFrameworkCore/blob/release/2.1/build/dependencies.props#L27

But the version of the assembly in the 4.5.0 NuGet package for net461 is 4.2.1:

image

However, the referenced assembly version in the EF assembly from the released 2.1.3 package is 4.2.0:

image

None of this makes sense to me...but that doesn't mean it's wrong. Is it wrong?

It’s not necessarily wrong because package version and assembly version don’t align. Corefx packages and assemblies version differently from aspnet. /cc @weshaggard

@natemcmaster But why would EF reference assembly version 4.2.0 when the package contains 4.2.1?

@ajcvickers Updating to VS 15.8.5 fixed the issue.

@ajcvickers as @natemcmaster states the package version and assembly version are intentionally not supposed to match because we have multiple versions of binaries in the packages so the package version matches all other packages released at the same time.

As for the ref and lib having different versions that is also intentional to handle issues where folks can reference this library and try to run on an older framework that has the library inbox, to prevent that from breaking we pin the version of the reference assembly for places where it might run on an inbox framework that has this older version (see https://github.com/dotnet/corefx/blob/master/src/System.ComponentModel.Annotations/ref/System.ComponentModel.Annotations.csproj#L6).

All that seems expected.

I couldn't figure out the minimal repo to try this out but from the discussion it definitely seems like an issue with binding redirects.

@weshaggard The following binding redirect was added automatically:

<assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />

This looks right to me, but isn't working. Here's the fusion failure from my machine:

=== Pre-bind state information ===
LOG: DisplayName = System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/Users/avickers/AppData/Local/JetBrains/Installations/ReSharperPlatformVs15_e3d70382/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = JetBrains.ReSharper.TaskRunner.CLR45.x64.exe
Calling assembly : Microsoft.EntityFrameworkCore, Version=2.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\Users\avickers\AppData\Local\JetBrains\Installations\ReSharperPlatformVs15_e3d70382\JetBrains.ReSharper.TaskRunner.CLR45.x64.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/Users/avickers/AppData/Local/JetBrains/Installations/ReSharperPlatformVs15_e3d70382/System.ComponentModel.Annotations.DLL.
LOG: Attempting download of new URL file:///C:/Users/avickers/AppData/Local/JetBrains/Installations/ReSharperPlatformVs15_e3d70382/System.ComponentModel.Annotations/System.ComponentModel.Annotations.DLL.
LOG: Attempting download of new URL file:///C:/Users/avickers/AppData/Local/JetBrains/Installations/ReSharperPlatformVs15_e3d70382/System.ComponentModel.Annotations.EXE.
LOG: Attempting download of new URL file:///C:/Users/avickers/AppData/Local/JetBrains/Installations/ReSharperPlatformVs15_e3d70382/System.ComponentModel.Annotations/System.ComponentModel.Annotations.EXE.
LOG: Attempting download of new URL file:///C:/Stuff/ef-13268-master/ef-13268-master/ef-13268/net_472/bin/Debug/System.ComponentModel.Annotations.DLL.
LOG: Assembly download was successful. Attempting setup of file: C:\Stuff\ef-13268-master\ef-13268-master\ef-13268\net_472\bin\Debug\System.ComponentModel.Annotations.dll
LOG: Entering run-from-source setup phase.
LOG: Assembly Name is: System.ComponentModel.Annotations, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: The assembly reference did not match the assembly definition found.
ERR: Run-from-source setup phase failed with hr = 0x80131040.
LOG: Attempting download of new URL file:///C:/Stuff/ef-13268-master/ef-13268-master/ef-13268/net_472/bin/Debug/System.ComponentModel.Annotations/System.ComponentModel.Annotations.DLL.
LOG: Attempting download of new URL file:///C:/Stuff/ef-13268-master/ef-13268-master/ef-13268/net_472/bin/Debug/System.ComponentModel.Annotations.EXE.
LOG: Attempting download of new URL file:///C:/Stuff/ef-13268-master/ef-13268-master/ef-13268/net_472/bin/Debug/System.ComponentModel.Annotations/System.ComponentModel.Annotations.EXE.
LOG: All probing URLs attempted and failed.

Yes that binding redirect looks correct however are you sure that one is being used?

LOG: Post-policy reference: System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

From the log it looks like it is using the 4.2.0.0 policy but not sure where that is coming from.

@AlexGhiondea @joperezr does this issue look familiar? I think System.ComponentModelAnnotations is inbox on .NET 4.7.2 and if that is the case it might be unifying down to 4.2.0.0 but even in that case I'd expect it to use find the one in the GAC if that were true.

If you have binding redirects in your application then we won't unify the reference -- we will use whatever version you have redirected to.

@AlexGhiondea Removing the binding redirect doesn't change the behavior.

@weshaggard @AlexGhiondea @joperezr Any further thoughts on this? Does it look like a bug--if so, where would the appropriate place be to file it?

@ajcvickers a couple comments above someone mentioned that upgrading to the latest VS solved the issue for them -- does that solve it for you?

@AlexGhiondea It solves it with the VS test runner, but not the R# test runner. If we're confident that this is a test runner issue then I will close, however the original report doesn't say anything about the test runner. More fundamentally, it doesn't seem like there is an understanding from anyone one on _why_ it is failing.

@ajcvickers I am glad to hear that this is partially addressed by an updated VS. Is there a way to get a minimal repro so that we can debug the loader and try to understand what is happening?

@AlexGhiondea Yes--it is referenced in this comment: https://github.com/aspnet/EntityFrameworkCore/issues/13268#issuecomment-424108108

One thing to note, is that there are some test runners that won't honor the App.config file so binding redirects are not used. That might explain why you have the redirect but it the loader is still trying to use a higher version. I'm not sure if the R# test runner is one of those who don't honor the config file though.

@ajcvickers Updating to VS 15.8.5 fixed the issue.

No, i'm updated VS to 15.8.5, but problem still exists.

I have similary problem, but haven't solution for it. If i use single project (EF Core SQlite WPF) - all just work. If I try to use separate project for UI (WPF) and data (EF Core + SQlite) - i have error: "Could not load file or assembly 'System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies".
I tried all of possible solutions from this issue and from other places, but still have this error again.

[rant]

For every new VS/MSBuild version, the dll hell is more and more evident. What I am unable to fathom, is why the endless problems with these assemblyredirects is not taken care of at all. After almost 30 years with build problems due to DLLs I do not see the end at all - it has actually never been as crazy as it is now. Could you please fix this, once and for all - and give us ways to upgrade from old .NET Frameworks, old csproj file structures, NuGet package upgrades etc etc. instead of giving the developers all the pain. Please.

[/rant]

Back from my illness I have a minimal demo project to reflect the issue

hope this helps. My suspicion, as already mentioned in a post above, that it has to do with separated projects...

Test.zip

@obelixA thanks for the repro project. I have tried that on my machine but I am unable to repro it. Do I ned to do any set up on the machine for the issue to repro or just opening the project and running should be enough?

@AlexGhiondea just open it and run (debug).
That's enough on my machine. When I am back on the machine I will provide details about VS...

I hope to get this solved soon, because no new releases are possible right now :-(

Here are the infos about VS

Microsoft Visual Studio Community 2017
Version 15.8.6
VisualStudio.15.Release/15.8.6+28010.2041
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Community

AnkhSVN - Subversion Support for Visual Studio 2.7.12815.35086
AnkhSVN - Subversion Support for Visual Studio 2.7.12815.35086

  • Ankh.Package 2.7.12815.35086
  • Subversion 1.9.5 via SharpSvn 1.9005.3940.224
  • Git/LibGit2 0.24.0 via SharpGit 0.2401.1116.230

SharpSvn is linked to: Apr 1.5.2, Apr-util 1.5.4, Cyrus Sasl 2.1.26, eXpat 2.2.0, LibSSH2 1.8.0, OpenSSL 1.0.2k 26 Jan 2017, Serf 1.3.9, SQLite 3.17.0, Subversion 1.9.5-SharpSvn, Utf8proc 1.1.5, ZLib 1.2.8
SharpSvn is optionally linked to: Berkeley DB 4.4.20, SharpPlink 0.67.0(SharpSvn)

SharpGit is linked to: Apr 1.5.1, Apr-Util 1.5.4, eXpat 2.1.0, Libgit2 0.24.0, LibSSH2 1.7.0, OpenSSL 1.0.2h 3 May 2016, Subversion 1.9.3, Utf8proc 1.1.5, ZLib 1.2.8

Application Insights Tools for Visual Studio Package 8.13.10627.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.8.05085.0
ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2017 5.2.60618.0
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0 15.8.05023.0
Azure App Service Tools v3.0.0

C# Tools 2.9.0-beta8-63208-01
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service 2.0
JavaScript Language Service

Microsoft Continuous Delivery Tools for Visual Studio 0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers 1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

NuGet Package Manager 4.6.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension 1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools 15.1.61808.07020
Microsoft SQL Server Data Tools

TargetFrameworkMigrator 1.0
Bulk Change .Net Projects Target Frameworks

TypeScript Tools 15.8.20822.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.9.0-beta8-63208-01
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual Studio Code Debug Adapter Host Package 1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers 1.0
Visual Studio Tools for Containers

Your zip file solution is not runnable on other machines, projects are missing

hmmm
seemed like @AlexGhiondea was able to run it. And I ZIPed the complete solution folder after "clean solution" - so I cannot imagine what is missing...

@obelixA I was able to run something, but I don't think I ran your repro as I didn't have an issue with what I ran. Having a simpler repro that we can run locally would be very useful!

hmmm
so please help me out. Simpler:
The TEST project consists of 1 WinForm doing nothing than referencing the DataReaderWriterSQLITE project, and the DataReaderWriterSQLITE consists of 2 *.cs files, one initializing the sqlite DB and one context throwing the exception when running.
I really do not know how to cut this down to a simpler version.
What I did is a "clean solution" before zipping. I can leave the compiled libs in the ZIP if that helps, or, please, teach me how to put it together.
this is my first time I need to provide someone with a stripped down project...

@obelixA this is what I see when I try to compile your project:

warning : The referenced project '..\..\Management\Manager\Manager.csproj' does not exist.
warning : The referenced project '..\..\Management\Types\Types.csproj' does not exist.

Those are warnings and if I continue to run the project, I end up with a running blank WinForms application. I don't see any errors or exceptions.

You are right! I missed to remove the references.
If you get a running app, this means you do not have the issue on your machine.
If I start the app, it calls "Form1_Load", within there a new "DataReaderSQLITE" Object is created.
Stepping into that the constructor creates a new LogContext.
Stepping into that, the LogContext inits the DB and in line 23 [this.Database.OpenConnection();] when opening the Connection the Exception occurs.

@obelixA thanks for the explanation. The code had a try/catch block around the exception which was hiding the actual issue.

I am going to take a look now that I have a repro.

I debugged this and what is happening is that the Winforms project does not have a dependecy to the System.ComponentModel.Annotations package.

That package is puled in by the Microsoft.EntityFrameworkCore reference in the DataReaderWriterSQLITE project. Because the package references are not transitively being included in the Winforms project you end up with that exception.

Please explicitly add the System.ComponentModel.Annotations package to the Winforms package. That has resolved the FileNotFoundException issue on my machine.

@AlexGhiondea Thanks for the info. How would a customer find out that this is needed?

How do I know which of the projects (in my real program, not in the test) do need the System.ComponentModel.Annotations package? The original project consists of 85 libraries...

Edit1: I because it did not help installing it to the corresponding WinForms project, I tried to install it into all projects. Compiled well, but still doesn't solve the main issue
Could not load file or assembly System.ComponentModel.Annotations, Version=4.2.0.0

@AlexGhiondea can you verify if this repros (Without the explicit reference to S.C.Annotations) when migrating the project to use PackageReference? I would expect that in that case the full package dependencies will be restored and added correctly, which would answer the question of what is the best way from a user's point of view to avoid these type of issues.

@AlexGhiondea Can you give some guidance on how to find out which projects will need to have the reference added?

@AlexGhiondea Here is another case where we need to give guidance as to what explicit references need to be added and why: https://github.com/aspnet/EntityFrameworkCore/issues/13619

Hi all!

I made the simple solution for demo of this error. In pdf-file step by step instruction for creating solution. In zip-file - archive of ready solution for testing. Sorry, "packages" folder removed from archieve (zip-file can not more than 10Mb)

AppTest8.Data — without packages folder.zip
How to get this error.pdf

@ajcvickers

Using PackageReference for your NuGet dependencies instead of using packages.config is the prefered way to ensure that all transitive dependencies flow correctly. If your main application doesn't have NuGet dependencies but instead has a Project-to-Project reference to a library that does have NuGet dependencies, the way to force your main application to use PackageReference model is to set this property on your main application's project:

<PropertyGroup>
  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

If your main application also has a NuGet dependency, then you don't have to set this property, all you need is to add your references to NuGet using the <PackageReference Include="Newtonsoft.Json" Version="11.0.2" /> model which would also fix this behaviour.

@joperezr Is there a place where this guidance is documented?

We are currently working on a Wiki page for all the related issues which should be a go-to page for anybody hitting them and will contain all this guidance.

@joperezr That's great. Is this work being tracked somewhere I can reference and point people to?

It's not yet tracked in github, we actually just had an internal meeting this morning to outline the work ahead. The plan is that once we have this wiki, we would come to all issues that are related and point them back to the wiki.

@joperezr Okay, thanks. I'll leave this issue open until we have somewhere to refer people.

If I got this right, I either have to add the Json Package to the main project (which references all the other projects), or add the PropertyGroup mentioned above.
Not to miss anything, I did both of it (and also already had a NuGet reference to TracerX).
And this sounds like a "BUT" and here comes the but: It changes nothing concerning the exception.
The Could not load file or assembly System.ComponentModel.Annotations, Version=4.2.0.0 Exception is still thrown when initializing the database project...
What did I miss?

Do you mind sharing a binlog of your build for the main project so that I can take a look? You can generate one by running msbuild yourMainProject.csproj /t:rebuild /bl /v:m which will create a msbuild.binlog file. Also, if you could attach your project.assets.json that gets generated in the obj directory of tha main project that would be great, as I would expect that project.assets.json to have the reference to System.ComponentModel.Annotations package.

hmmm... may be that doesn't work:

**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.8.7
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cd C:\Programmierung\acs-Kasse-GIT\Programme\acs-Kasse>
Syntaxfehler.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cd \Programmierung\acs-Kasse-GIT\Programme\acs-Kasse>
Syntaxfehler.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>cd \Programmierung\acs-Kasse-GIT\Programme\acs-Kasse

C:\Programmierung\acs-Kasse-GIT\Programme\acs-Kasse>msbuild acs-Kasse.csproj /t:rebuild /bl /v:m
Microsoft (R)-Build-Engine, Version 15.8.169+g1ccb72aefa für .NET Framework
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\msbuild.exe /bl /t:rebuild /v:m acs-Kasse.csproj
SpringCardPCSC_Calypso.cs(99,10): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.ShortId' is never u
sed [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(103,10): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.NumRec' is never u
sed [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(106,9): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.Status' is never us
ed [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(105,9): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.NKey' is never used
 [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(101,10): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.SubType' is never
used [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(100,10): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.Type' is never use
d [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(104,9): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.AC' is never used [
C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(102,10): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.RecSize' is never
used [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
SpringCardPCSC_Calypso.cs(107,11): warning CS0169: The field 'SCardCalypso.CALYPSO_CD97_FILE_INFO_ST.KVC' is never used
 [C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\SpringCard.csproj]
  SpringCard -> C:\Programmierung\acs-Kasse-GIT\Management\SpringCard\bin\Debug\SpringCard.dll
  Tools -> C:\Programmierung\acs-Kasse-GIT\Management\Tools\bin\Debug\Tools.dll
  Newtonsoft.Json.dll
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
  Tools.dll
  TracerX-Logger.dll
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
          0 Datei(en) kopiert.
  Tools.pdb
  TracerX-Logger.pdb
          0 Datei(en) kopiert.
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(
5158,5): error MSB3073: Der Befehl "copy *.dll *Undefined*\bin\Debug\ [C:\Programmierung\acs-Kasse-GIT\Management\Tools
\Tools.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(
5158,5): error MSB3073: copy *.PDB *Undefined*\bin\Debug\" wurde mit dem Code 1 beendet. [C:\Programmierung\acs-Kasse-G
IT\Management\Tools\Tools.csproj]
  ZIPHelper -> C:\Programmierung\acs-Kasse-GIT\Management\ZIPHelper\bin\Debug\ZIPHelper.dll
  ICSharpCode.SharpZipLib.dll
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
  ZIPHelper.dll
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
          0 Datei(en) kopiert.
  ZIPHelper.pdb
  Die Syntax für den Dateinamen, Verzeichnisnamen oder die Datenträgerbezeichnung ist falsch.
          0 Datei(en) kopiert.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(
5158,5): error MSB3073: Der Befehl "copy *.dll *Undefined*\bin\Debug\ [C:\Programmierung\acs-Kasse-GIT\Management\ZIPHe
lper\ZIPHelper.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets(
5158,5): error MSB3073: copy *.PDB *Undefined*\bin\Debug\" wurde mit dem Code 1 beendet. [C:\Programmierung\acs-Kasse-G
IT\Management\ZIPHelper\ZIPHelper.csproj]

C:\Programmierung\acs-Kasse-GIT\Programme\acs-Kasse>

I still will follow any suggestions AND additionally I still offer the remote session to my development machine, so all libraries and projects are in place...

Did some testing by adding System.Componentmodel.Annotation and System.Componentmodel.DataAnnotation. None of my combinations did the trick :'-(
I have really no idea, what else I could try...

@obelixA did running msbuild /t:rebuild /bl generate a msbuild.binlog file on your working directory? If so, can share that please?

Hi
yes! It did. I oversaw it trying to understand how to avoid the error messages and get a working build...
attached please find the file...
msbuild.zip

Experienced same issue in asp.net solution in integration tests project while porting EF->EF Core.
Fixed with adding following binding redirect to IntesrationTests/app.config.
First adding following binding redirect to each and every app.config/web.config fixed that error, than narrowed down to the integration tests' app.config itself

<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.ComponentModel.Annotations" culture="neutral" publicKeyToken="b03f5f7f11d50a3a" />
                <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

@joperezr More customers are reporting this--see above and #13756. Do we have any answers for them yet?

We are still working on the Wiki page. I will update this thread once we have that information available.

the final solution may be unbelievable superb - but is there any (working!) work around to get development running again?

@obelixA Sorry, I'm as much in the dark as you are. Just waiting to here back from @joperezr at this point.

@obelixA By looking at your msbuild.binlog I believe you haven't yet applied the workaround I suggested. Looks like your Manager.csproj needs a property to be set in order for dependencies to flow correctly, so please set the following property into your Manager.csproj:

<PropertyGroup>
  <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

@joperezr I did. Believe me ;-)
But it did not change anything.
As my grandmother said: much helps much, I added it to each of the 86 projects, clean and rebuild, but didn't work either.

@joperezr please see #13756. I did your "workaround" before hitting this (or a similar) issue. Could you please have a look?

@obelixA is that missing assembly even not copied to your output folder? In my case it is copied but if I deploy it I get a similar error like you, but my one argues with the manifest version of that assembly. At least the assembly is found in my case...

@JojoEffect: nope, I really have version 4.2.1.0 in the output directory. Version 4.2.0.0 is missing. As far as I understood this mechanism, version 4.2.1.0 should be used even if 4.2.0.0 is needed (hoping for down compatibility) through magic "PackageReference" Voodoo :-D
If not, I am willing to read about it (link appreciated) to dig deeper into that and to better understand what's going on behind the scenes...

if the information on the wiki page are the same like the suggestions here, that do not work up to now, the whole wiki is useless. If we would have working suggestions here already, I would understand to bundle those information on a central page... strange...

@joperezr Another customer reporting the same thing: #13956 How close are we to being able to help customers fix these problems?

Is there any work around for this? Something that we can manually do to get this working. We have tired loading the System.ComponentModel.Annotations.dll product version 4.6.26515.06 manually with Assembly.LoadFile to see if that would resolve this issue, and the error still happens.

@ravenboilinux I'm happy to take a look at your binlog file in order to help you fixing the issue. In order to produce a binlog, just run msbuild yourProject.csproj /t:rebuild /bl:msbuild.binlog from a developer command prompt. If you send that out, I can find out what is going on.

msbuild.zip
@joperezr here is the zip version of the binlog

@ravenboilinux I don't think yours is a dupe of this one, yours seem a bit different after looking at the binlog. I'll re-open the other issue you logged so that we can follow the investigation there.

@joperezr would it help if I provide my binlog too?

@obelixA I got mine to work.

I'm working on a project that uses System.ComponentModel.Annotations 4.4.1 and I referenced everything as described. However, I was getting the same error everybody else is currently getting. I decided to reference System.ComponentModel 4.3.0 and I don't get the error anymore. Seems that there is a dependency that was not enforced in Nuget.

@JamesJohn93: unfortunately it doesn't work. I even downgraded to 4.1.0
I could cry all day long... No solution...

using assembly redirection worked for me: https://stackoverflow.com/a/50776946/2705777

@neil-rubens: THANK YOU VERY MUCH!!!
this solves the issue.
Unbelievable that the cause to switch to the new VS project files (automatically resolving version "conflicts" with assemblies) is the reason for those deep problems. And second unbelievable that MS cannot solve this internally. There has to be a customer to get deep into the resolving issues and hand out a solution.
In my case, due to the fact that it only happens framework core internally while updating the database, it is enough to redirect the resolver when starting the program, and stopping it (by unregistering the event) when main form and dlls are loaded. while the program is running everything seems to be ok. And if some day the exception occurs while executing any db operation, I can prevent this by not unregistering the event.

Despite from having a solution that works for me and for now, it would be a more reliable solution if this is fixed Microsoft internally...

In some form this problem is already there for more then two years. In my experience it only shows up in rather complex solutions were both .Net Core (EF Core) and traditional .Net Frameworks (both 4.6.1 and 4.7.2) are used. Since the introduction of .Net Core 2.1 the problem can nearly always be solved by manually editing your config file in one or more projects (app.config in my case). Include the lines below in the runtime section.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
  <dependentAssembly>
     <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

This did not work for me - may be because I do not know which *.config files are affected. There are many relations so I guess there should be entries in the config file, where I do not think they should be needed. The whole solution is 86 projects. Adding the lines to the config files where database (ef core with .Net Core) is used, it still throws the exception, Adding them to config files of "higher" projects (that make use of projects with database) still doesn't to the trick.
A solution like yours would again speedup the application start by far - the assembly resolver is little slow...

Same issue:

Error CS1061: 'DbContextOptionsBuilder<MemoryContext>' does not contain a definition for 'UseInMemoryDatabase' and no accessible extension method 'UseInMemoryDatabase' accepting a first argument of type 'DbContextOptionsBuilder<MemoryContext>' could be found (are you missing a using directive or an assembly reference?)
Process 'msbuild.exe' exited with code '1'.

It is working locally, but VSTS throws the exception above.

Closing this in favor of https://github.com/dotnet/corefx/issues/33643. (I was keeping this issue open to try to get some traction on figuring out what is going wrong, even though this does not seem to be an EF issue. However, since it's not an EF issue, going forward it will be tracked elsewhere.)

JRBonnema's code worked for me. I had to use newVersion="4.0.0.0" even though I had 4.5 installed.

In some form this problem is already there for more then two years. In my experience it only shows up in rather complex solutions were both .Net Core (EF Core) and traditional .Net Frameworks (both 4.6.1 and 4.7.2) are used. Since the introduction of .Net Core 2.1 the problem can nearly always be solved by manually editing your config file in one or more projects (app.config in my case). Include the lines below in the runtime section.

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
  <dependentAssembly>
     <assemblyIdentity name="System.ComponentModel.Annotations" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
     <bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

LOVE YOU ^
MS - Can this not simply be fixed already this kind of stuff is really confusing!!!

None of the above solutions worked for me so for a .NET 4.7.2 console application which is going to be run as a Windows Service.
It's complaining about not finding the System.ComponentModel.Annotations 4.2.0, but there doesn't even seem to be such a version, especially not on nuget.
Almost 2021 and still in DLL Hell as it seems.

Still get this issue. Working fine locally but doesnt work in vsts test runner.

Was this page helpful?
0 / 5 - 0 ratings