microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.34k stars 2.21k forks source link

System.ComponentModel.Annotations assembly not found error again #584

Closed codearoo closed 6 years ago

codearoo commented 6 years ago

I don't know which of the many Microsoft teams to post this with. Last time we updated our NuGet packages, we had this error and now when we just did it recently it happened again. We updated to 4.4.0. And the project file of a particular Test project type ends up with this: `

..\packages\System.ComponentModel.Annotations.4.4.0\lib\net461\System.ComponentModel.Annotations.dll
</Reference>

` And it complains it can't find ver 4.2.0.0. But when I change it manually it doesn't seem to help.. it now fails to find that version. I know previously there was something really messed up like it was actually 4.0.2.0 not 4.2.0.0 or whatever.. so we had to manually fix the project or app.config file. I have no idea how to find that version number now (Windows 10 details of a DLL no longer see to show assembly versions, just file version which is 4.6.25519.3.

What the heck is going on? When is this absurd thing going to get fixed? Lots of posts about this weird versioning problem.. it's as if the old VB6 days are back with DLL hell.

I don't understand why anything needs to show up in app.config anyway for these DLL references when it's all done through NuGet. What a mess. I'm going to try with today's update of 4.4.1 .. 1st attempt was that all kinds of references failed. Undoing that and will try again later.

codearoo commented 6 years ago

So I had to manually add `

    <bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
  </dependentAssembly>

` To the app.config file of the project to make it work. But this test project has been working for months and this ComponentModel.Annotation section in the app.config was NOT in there. I just verified in our repo history.

richlander commented 6 years ago

PTAL @terrajobst @AlexGhiondea

StefanoD commented 6 years ago

Same problem here.

camainc commented 6 years ago

Same problem here

ericnewton76 commented 6 years ago

We are back to Guid DLL hell due to the restrictive versioning scheme used by fusion. It simply must be changed to semver without needing those binding redirects.

It’s time for the net assembly loader to be configurable and allow for looser semver strategies for assembly binding. Non major specific version mismatches should be fusion log warnings.

terrajobst commented 6 years ago

As @ericnewton76 said, these problems are a result of the .NET Framework binding policy, which is exact match only. Everything else requires binding redirects. Thankfully, since .NET Framework 4.5.2 you can configure your project to automatically produce the correct binding redirects without having to mess with your app.config file.

It’s time for the net assembly loader to be configurable and allow for looser semver strategies for assembly binding

All .NET binders that were built after .NET Framework behave this way (Mono, Silverlight, Phone, Xamarin, .NET Core, etc). We're extremely unlikely to add this feature to the .NET Framework due to cost, complexity, and backwards-compatibility concerns.

terrajobst commented 6 years ago

@codearoo

Given my earlier response, I'm going to close this.

camainc commented 6 years ago

Thankfully, since .NET Framework 4.5.2 you can configure your project to automatically produce the correct binding redirects without having to mess with your app.config file.

Well, I tried that first and unfortunately it did not work for me. I had to add the entry to my web.config. I can upload my project file in case anyone wants to look at it. Maybe I didn't follow the instructions correctly.

camainc commented 6 years ago

ProjectFile.zip

terrajobst commented 6 years ago

@camainc

Unfortunately, automatic binding redirects don't work for web.config (as the build doesn't produce a config file; instead, it uses the one from your project directly). However, you don't have to hand-edit the config file. When binding conflicts occur, you'll get a warning in the Error List. You can double click the warning which will then prompt you to confirm that you want the binding redirects added to your project file.

camainc commented 6 years ago

" When binding conflicts occur, you'll get a warning in the Error List. "

I was getting a run-time error. I commented out the dependent assembly section from my web config and ran it again. It breaks when attempting to use the DbContext. The error in this screenshot is happening during the IOC container resolution.

image

camainc commented 6 years ago

Here are the details:

Exception thrown: 'System.IO.FileLoadException' in mscorlib.dll 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) occurred

camainc commented 6 years ago

I looked through the warnings for my web project, and there was nothing there about the System.ComponentModel.Annotations.

I have these two entries in my project file: image

I initially had them in their own PropertyGroup element, but that didn't seem to make any difference. Then I moved them up into the first ProjectGroup element in the project file, and that doesn't seem to make any difference either. I still see a warning asking me to add AutoGenerateBindingRedirects to my project file, but it is already in there:

image

When I comment out all of the dependent assembly references from my web config, I get a boatload of messages in the build output like this:

9> No way to resolve conflict between "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" and "Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed". Choosing "Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" arbitrarily. 9> No way to resolve conflict between "System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.ComponentModel.Annotations, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Choosing "System.ComponentModel.Annotations, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" arbitrarily. 9> No way to resolve conflict between "Autofac, Version=4.8.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da" and "Autofac, Version=3.5.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da". Choosing "Autofac, Version=4.8.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da" arbitrarily. 9> No way to resolve conflict between "Telerik.JustMock, Version=2018.1.117.2, Culture=neutral, PublicKeyToken=721b6c5bc0326b3a" and "Telerik.JustMock, Version=2015.3.929.5, Culture=neutral, PublicKeyToken=721b6c5bc0326b3a". Choosing "Telerik.JustMock, Version=2018.1.117.2, Culture=neutral, PublicKeyToken=721b6c5bc0326b3a" arbitrarily. 9> Consider app.config remapping of assembly "System.Runtime.Serialization.Xml, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "4.0.10.0" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.2\Facades\System.Runtime.Serialization.Xml.dll] to Version "4.1.3.0" [C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Runtime.Serialization.Xml.dll] to solve conflict and get rid of warning. 9> Consider app.config remapping of assembly "System.Data.Common, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" from Version "0.0.0.0" [] to Version "4.2.0.0" [C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\MSBuild\Microsoft\Microsoft.NET.Build.Extensions\net461\lib\System.Data.Common.dll] to solve conflict and get rid of warning.

Izzmo commented 5 years ago

Any updates?

terrajobst commented 5 years ago

My comments from above are still the current state of the world. .NET Framework web projects don't support automatic binding redirects, you have to manually add them to your web.config, but usually you'll get warnings you can double click and the will add the correct binding entries in your web.config file.