Version-specific assembly references when Specific Version is False - visual-studio

I've recently started having problems with my projects wanting specific versions of their referenced assemblies even though the references are marked as Specific Version = False in my Visual Studio project. For example, I'll replace MyAssembly.dll version 1.0.0.0 with MyAssembly 1.0.1.0 and the applications referencing MyAssembly.dll will get an error saying version 1.0.0.0 cannot be found. The specific version property doesn't seem to be working. This is a huge pain because I have to rebuild and redeploy every application that references the assembly even if there are no breaking changes in the new version. I know in the past when this has been false it would use any version and if more than one was found it would use the latest version. Does anyone know what the problem is?
Edit: This has been open with no responses for a while. Is the question unclear? What I want to know is, is there a way to update assemblies my .NET application depends on to a new version without rebuilding my .NET application.

Hi I just had the same problem with a Sharepoint project and I fixed it by editing the app.config file and add the following ind the configuration tag. That did the trick..
The Specific Version is a compile time issue.. I didn't know that.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SharePoint.Dsp" publicKeyToken="71e9bce111e9429c" culture="neutral" />
<bindingRedirect oldVersion="11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
<runtime>

Related

Windows Forms Designer Crashes Visual Studio, can't find System.ComponentModel.Annotations

I have a solution structured as such:
MyDataAccessLibrary.csproj (.NET Standard 2.0)
Nuget packages include
Microsoft.EntityFrameworkCore 3.1.3
System.ComponentModel.Annotations 4.7.0
MyApplication.csproj: Windows Forms app (.NET Framework 4.8), uses Package References for dependencies
System.ComponentModel.Annotation 4.7.0
In the Windows Forms application, there is a form (MySuperForm) with a property defined in MyDataAccessLibrary (that type is also an entity type referenced through the DbContext with a DbSet) that serves as a super class to a dozen or so other forms in the project. MySuperForm opens without issue in the forms designer.
The project compiles and runs without problems.
However, attempting to open any of the forms subclassed from MySuperForm gives a designer error:
Could not load File or Assembly System.ComponentModel.Annotations version 4.2.0.0.
And Visual Studio 2019 subsequently crashes and restarts (Version 4.8.03752).
My app.config file contains the following Binding Redirect:
<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.2.1.0" />
</dependentAssembly>
</assemblyBinding>
Which is what was generated by using the Auto-generate binding redirect option in the project properties. Note that confusingly, the 4.7.0 version of the Nuget package includes 4.2.1.0 of the actual file, and the dll copied into the bin folder shows version 4.7.26515.06.
I have tried adding the Microsoft.EntityFrameworkCore 3.1.3 package to the application even though no code in that app directly references it (package references bubble up the transitive dependency).
The same version of System.ComponentModel.Annotations is used by all referenced projects in my solution.
I have cleaned, rebuilt, cleared cache, deleted bin and obj folders repeatedly. How can I get these forms to open in the designer?

assemblyBinding understanding Newtonsoft.Json and Common.Logging connection

I added to my project Newtonsoft.Json via Nuget.
After I did that I found VS added these section:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Q1: Why is it doing that? What is the purpose?
Q2: Why does Common.Logging appear there as well? I never added Common.Logging via Nuget.
Q3: Do I need to add Common.Logging via Nuget? I tried, installed Common.Logging via Nuget via Nuget and found out it also installed Common.Logging.Core. But the config section above did'n change!
Can someone explain me in very simple language without copy-pasting from MSDN what this whole circus is for? How does it work, and why Common.Logging suddenly was added to this section, do I actually need to install it along with Common.Logging.Core, when I need only Newtonsoft.Json?
Thanks.
Q1: Why is it doing that? What is the purpose?
Simple language is that if two components reference different versions of the same strong-named assembly, the runtime automatically adds a binding redirection to the newer version of the assembly in the output app configuration (app.config) file.
For example, you have application A that references library B, and also library C with version 1.0.0.0. Library B in turn also references library C, but the version 1.1.0.0. Now we have a conflict, because you cannot load different versions of the same assembly at runtime. To resolve this conflict you might use binding redirect.
If you are interested, you can see Redirecting Assembly Versions for more details
Q2: Why does Common.Logging appear there as well? I never added
Common.Logging via Nuget.
Not sure why it also add Common.Logging. It may be more related to your project. Probable, your project indirectly references this nuget package as reference or your project reference this assembly directly. Because Add-BindingRedirect will examines all assemblies within the output path for a project and adds binding redirects to the application or web configuration file where necessary.
Certify: Add-BindingRedirect
Q3: Do I need to add Common.Logging via Nuget? I tried, installed
Common.Logging via Nuget via Nuget and found out it also installed
Common.Logging.Core. But the config section above did'n change!
If you can make sure you only need Newtonsoft.Json, you do not need to add Common.Logging via Nuget.
Hope this helps.

Assembly binding redirect from a Class Library

I have a GitHub project (Test Automation Essentials) which references some Visual Studio specific assemblies (Microsoft.VisualStudio.TestTools.UITest.Extension which is part of CodedUI; but that's not significant for the question). This project is published as a NuGet package containing my class library.
I want my project to support different versions of Visual Studio, and all in all, this assembly does not have any noticeable differences between the versions of Visual Studio, so I don't anticipate any compatibility issues (it should be backward compatible anyway).
However, if I compile my project in one version of Visual Studio (e.g. 2015), when I try to reference the NuGet package from a project in a newer version of Visual Studio (e.g. 2017), when the hosting project runs I get the following exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TestTools.UITest.Extension, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file
Note: my library references this assembly with Specific Version=False.
I found I can work around this issue by adding the following element to the app.config of the application:
<dependentAssembly>
<assemblyIdentity name="Microsoft.VisualStudio.TestTools.UITest.Extension" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="12.0.0.0-15.0.0.0" newVersion="15.0.0.0"/>
</dependentAssembly>
Note: In this particular case the executable is typically QTAgent32_40.exe which is itself part of Visual Studio, so I had to add the element to QTAgent32_40.exe.config and not actually to the project's app.config file. QTAgent32_40.exe.config already has many similar dependentAssembly elements, but for some reason not for this specific assembly.
The question:
I don't want my clients to add this setting themselves. I'd be glad if I could have such a setting specific for my class library, so that anyone who references my library automatically gets this Assembly Redirect setting. However, I didn't find a way to do that...
Does anyone knows how can I do it?
The only way to do this is to create a Nuget package for each specific version of Visual Studio.

Compilation Error (Website Not Recognizing .NET 4.5)

I am trying to get a website to recognize a new version of .Net (4.5) so that I can upgrade to the final version of DNN (7.2). I have .Net 4.5 installed but when I go into the IIS settings, switch the framework to 4.5 (it actually says 4.0 bc the version is technically 4.03), and then refresh local host I get the error:
"Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1703: An assembly with the same identity 'System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' has already been imported. Try removing one of the duplicate references.
[No relevant source lines]"
Haven't found anything useful thus far on the web regarding this. Please Help!
Update: the version referenced in the web.config does say 3.5.0.0 Is this the issue?
Your website only needs to be configured to use .Net 4.0
.Net 4.5 is an extension of the version 4.0.
Depending on the method you use to switch from .Net 2.0 to .Net 4.0, you would have to replace references to version 3.5 by references to version 4.0 in your web.config.
I was moving a dnn site from SSMS 2008 to 2012 to upgrade a DotNetNuke 4.8.0 site to 5.4.0 (I know it's old and that it's 5.4 and stable, I can continue the upgrade path) and came across the Compiler Error Message.
Compiler Error Message: CS1703: An assembly with the same identity
'System.Web.Extensions, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad36e35' has already been imported. Try
removing one of the duplicated references.
I replaced two references to 3.5 to 4.0 in web.config and it fired right up after I replaced the old core files with the 5.4 upgrade files.
I had a similar build error:
An assembly with the same identity 'System.Runtime, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' has already been
imported. Try removing one of the duplicate references.
The problem was with <assemblyBinding> in web.config. I had to change
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.10.0" newVersion="2.6.10.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
To (note the binding redirect versions)
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I think the original assembly binding redirect was added when I upgraded the site from asp.net 2.0 to 4.0. For some reason this worked on one of my machines but when I checked out the project on another machine the build failed.
In my case, I've installed something from Nuget (Humanizer) and it created a folder in my web site called packages where it added new references to basically every knwon .net class (it seems that it needed to resolve some dependencies - a lot of dependencies!! :)) ), that is why I had multiple references to a lot of .net classes. I've removed that package entirely and it removed with it all other dependency references.
Now all is ok.. thank God! :)

Code Analysis error Could not load file or assembly 'System.Net.Http, Version=2.0.0.0 in MVC4 Web API

this problem is exactly the same as this post http://forums.asp.net/t/1807797.aspx/1?System+Net+Http+is+not+found and this one on StackOverflow
I have all the latest RTM bits, Started a new MVC 4 in .Net 4.5, added the WebAPI nuget package and now my code analysis fails with the same error as reported in the above link.
CA0058 Error Running Code Analysis CA0058 : The referenced assembly 'System.Net.Http, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' could not be found. This assembly is required for analysis and was referenced by: C:\Projects\InHouse\TimeRecorder\StopGap\TimeRec\bin\TimeRec.dll, C:\Projects\InHouse\TimeRecorder\StopGap\packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40\System.Web.Http.dll. [Errors and Warnings] - (Global)
From what I can find this seemed to happen with the RC versions because there was a conflict between the .NET 4.5 framework System.Net.Http and the WebApi's version of the System.Net.Http.
The other answers on the StackOverflow response talk about downgrading from .Net 4.5 to 4.0, for obvious reasons, this is not my preferred solution!
Try the following:
Depending on your Visual Studio edition navigate to:
VS 2010:
%ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop
VS 2012:
%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Team Tools\Static Analysis Tools\FxCop
Open FxCopCmd.exe.config and change AssemblyReferenceResolveMode
from StrongName to StrongNameIgnoringVersion.
Save the change and rebuild your project.
From Visual Studio 2012 and higher, instead of modifying your installation files, use the workaround specified here: Using Microsoft.Bcl.Async with Code Analysis causes errors.
I have had the same problem (couldn't build locally and remotely on azure).
This workaround helped me:
http://connect.microsoft.com/VisualStudio/feedback/details/760208/nuget-package-for-asp-net-mvc-4-web-api-does-not-reference-correct-net-4-5-assemblies#
here is the part you need:
Copy the System.Net.Http.dll and System.Net.Http.xml files contained in the packages\Microsoft.Net.Http.2.0.20710.0\lib\net40 directory to the packages\Microsoft.AspNet.WebApi.Core.4.0.20710.0\lib\net40 directory. Since the missing System.Net.Http.dll assembly is now in the same location as the referenced System.Web.Http.dll assembly, the code analysis can now properly resolve the conflicting System.Net.Http assembly.
The issue is caused because you have a dependency on a newer version of System.Net.Http, than that required by one of the other assemblies referenced.
The correct way to resolve this issue is to add dependentAssembly redirects to the app.config of offending projects. The accepted answer of disabling the errors just masks an underlying problem.
Add the following to the runtime section of app.config to remap the old version that can't be resolved to the version referenced in your project. The version numbers should obviously be updated to correspond to your situation.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

Resources