Using dotPeek to examine the references of the main assembly of a web project, I see:
System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
The project references in Visual Studio only shows version 5.2.3.0. I've also searched the .csproj files of referenced projects.
Manage NuGet Packages only shows v5.2.3 of Microsoft.AspNet.Mvc.
Searching the packages folder only finds v5.2.30128.0 under Microsoft.AspNet.Mvc.5.2.3\lib\net45.
gacutil /l System.Web.Mvc shows versions 3.0.0.0 and 4.0.0.0.
I've looked through the other references with dotPeek's References Hierarchy and I didn't find the old version.
Per a reply I checked the Web.config; this was already present:
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
I also checked other Web.configs for conflicting versions.
In addition I tried setting Specific Version to True in the System.Web.Mvc reference properties. This made no difference.
Are the multiple versions expected? If not, how can I find and remove the source of the old version?
try adding this to your web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
This basically test your application that for any version (from 1-5.2.3) of System.Web.MVC that is referenced in the application to use 5.2.3.0 instead. more than likely you have a reference that still is looking for the specific version of 5.0. This burns me all the time with JSON.net.
Remove multiple existing dependency from reference. After that add reference that you want to keep in your project.
And from property window you can see the version on current dependency. Check that version from that and set version in web.config file.
Related
I'm getting the following exception when trying to call GetDatabase method of the MongoClient class after adding a new configuration using VS config. manager:
Could not load file or assembly 'System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
I installed the latest System.Buffer nuget package v4.5.1, created dependentAssembly in my app.config and Reference in my .csproj file, but I still have the same issue. For some reason it tries to reference System.Buffer with v4.0.2. Has anyone had a similar error and how did you solve it?
Could not load file or assembly 'System.Buffers, Version=4.0.2.0…'
Solution
1) use CMD(run as Administrator ) and type
cd xxxx(xxxx\packages\System.Buffers.4.5.1\lib\netstandard2.0))
run
gacutil /i System.Buffers.dll
Then, when you finish it, please run update-package -reinstall under package manager console to reinstall the package.
2) you can try to change Version=4.0.2.0 to Version=4.0.3.0 in csproj file.
Besides, there is a similar issue you can refer to.
The easiest way is to use Nuget package manager, downgrade system.buffers to any lower version, and then upgrade it to the latest again.
In my case, I had to add the assembly reference in the web.config that was already published in the Azure App Service, inside the <configuration></configuration> tag:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
I ran into this issue when adding the Azure.Storage.Blobs package to a Class Library where I was attempting to create a blob uploader client. When I added the package, it created an app.config with the correct binding redirect:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
</dependentAssembly>
<dependentAssembly>
The issue, however, is that this binding redirect needs to live in the app.config of the application, not the class library: Can a class library have an App.config file?
So, adding the binding redirect is the correct way to solve this issue. Just make sure the binding redirect is specified in the calling web/console/etc app.
Another solution: just remove references to the assembly in the Web.config files of the projects generating the exception.
The references can look like:
<dependentAssembly>
<assemblyIdentity name="System.Text.Encodings.Web" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.0" newVersion="4.0.4.0" />
</dependentAssembly>
I ran into a similar issue, tried all the steps above. In the end, another project had an older version of the same library. Too many projects in the solution, the other reference was scrolled out of view.
Recently I have started using SSMS 2017 (v17.5). In my MVC application, I am getting Could not load file or assembly 'Microsoft.SqlServer.Types, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. error. Only thing changed in my application is Microsoft.SqlServer.Types version which is 14.0.0.0 now. Previously, it was 12.0.0.0.
Following are different options I have tried so far based on my research (this includes another stackoverflow articles + google) but I am getting same error.
Add <dependentAssembly> in app.config
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="10.0.0.0-11.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
Adding following line in Global.asax.cs in Application_Start method.
SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91";
Installing Microsoft.SqlServer.Types using NuGet.
PM> Install-Package Microsoft.SqlServer.Types
Searched for 10.0.0.0 referance in entire project but didn't find any referance.
I do have Microsoft System CLR Types for SQL Server installed for 2012, 2014, 2016 and 2017.
What am I missing here?
After spending almost a day, I was able to fix this issue. From my question above, option-1 worked for me. Only tweak was to add that in web.config instead of app.config. Hope this help someone else.
Code: web.config
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-14.0.0.0" newVersion="14.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Microsoft.SqlServer.Types -Version 14.0.314.76 is the current version. try changing your version number. Second, check your .csproj file, Application also maintains its dependencies in .csproj file
For a net library project that have the same error, I go to NuGet packages and install this library:
Microsoft.SqlServer.Types
and its works.
I'm using WebmarkupMin in some of my projects for some time now but when i started a new project today i had this problem with it's version and MVC version.
I'm using .NET MVC 3 and Visual Studio 2012, i already checked the version of WebMarkupMin on the website and it's ok, i downloaded it using NuGet, already tried to remove and add it again and nothing.
Assembly 'WebMarkupMin.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=99472178d266584b'
uses 'System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
which has a higher version than referenced assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' d:\Jobs em Andamento\Skill2015\packages\WebMarkupMin.Mvc.1.0.0\lib\net40\WebMarkupMin.Mvc.dll
My web.config also has a assembly binding that was there before i installed the WebMarkupMin:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
</assemblyBinding>
I already tried to change the older version to 3.0.0.1 but i still get the same error.
How can i fix that ?
Try this:
<bindingRedirect oldVersion="0.0.0.0-3.0.0.1" newVersion="3.0.0.1" />
The problem in my case was that when i added a third part lib ( HtmlAgilityPack ) it changed my version of the Razor dll in my packages.config, after i removed the reference from the project, changed the version on the packages.config and added a reference to the older version everything worked fine.
We're using Visual Studio 2010 and we recently started using Google API.
Due to irrelevant reasons, we cannot use NuGet Package Manager for handling dependencies. Instead, what we did was something similar.
We created a libraries folder in our solution root so all our projects would reference the same libraries, pretty much what NuGet does, but without the Package Restore or the ease to update.
We added the following references to our project:
Along with the appropiate dependencies:
Microsoft.Bcl
Microsoft.Bcl.Async
Microsoft.Bcl.Build
Microsoft.Net.Http
Newtonsoft.Json
ZLib
However, when trying to compile my project, the following error shows up:
The type or namespace name 'Apis' does not exist in the namespace 'Google' (are you missing an assembly reference?)
The strange thing is that right after my building fails, IntelliSense won't detect any Apis namespace, just as the compiler is telling me.
But if I remove the dependency and add it again, then it finds it.
After this point, if I try to compile the project again, the process would fail, and IntelliSense would (again) fail to find the Apis namespace.
We already tried deleting temporary files, but with no luck.
What may be happening?
UPDATE
I began to notice some warnings:
The primary reference "System.Net.Http.Extensions" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework, Version=4.0". To resolve this problem, either remove the reference "System.Net.Http.Extensions" or retarget your application to a framework version which contains "System.Net.Http, Version=1.5.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
I am currently targeting .NET v4, and I indeed have the System.Net.Http assembly being referenced from the project.
The same warnings shows up for the following assemblies:
Microsoft.Threading.Tasks.Extensions
Microsoft.Threading.Tasks
Google.Apis.PlatformServices
Google.Apis.Core
Google.Apis.Auth.PlatformServices
Google.Apis.Auth
Google.Apis
My System.Net.Http is version 2.2.28.0, which explains the warning, because System.Net.Http.Extensions is looking for version 1.5.0.0.
This led me to create the following app.config which should remove the version conflicts:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.13.0" newVersion="1.2.13.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
The same errors and warnings appear.
The problem seems to be with assembly redirect in class library projects. It doesn't happen when using NuGet, since NuGet adds Microsoft.Bcl.Build.target file that redirects the DLLs (see this question for more details).
There seems to be 3 possible solutions to this:
Install the packages using NuGet.
Download the DLLs and reference them in a console application project, along with app.config with assembly redirect.
Download the DLLs and reference them in a class library, and do the following:
Copy locally the package Microsoft.Bcl.Build.1.0.14, and add the following to your class library csproj:
<Import Project="..\PACKAGE_LOCATION\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\PACKAGE_LOCATION\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
(Replace PACKAGE_LOCATION with the location of the Microsoft.Bcl.Build.1.0.14 package)
If other projects reference your class library, you will then get an error:
warning : All projects referencing MyProject.csproj must install nuget package Microsoft.Bcl.Build
To solve that you'll have to add the DLLs and the Microsoft.Bcl.Build.targets to all the referencing assemblies (see this for more information).
Hope this helps.
After adding WebAPI and register it in Global.asax.
We find our web app breaks at this line:
Line 17: GlobalConfiguration.Configure(WebApiConfig.Register);
Error message:
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral,
PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies.
The system cannot find the file specified.
After some checkup, I find we are using Json.net 6 in this MVC 5.1 application. Does it mean we have to downgrade to Json.net 4.5 for WebAPI to work?
In my .csproj file, there is only one entry:
<Reference Include="Newtonsoft.Json, Version=6.0.3.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
When I look into my Json.NET in Manage NuGet Packages, it also says my Json.NET is version 6.0.3.
In addition, there is already the bindingRedirect statement in my web.config.
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
But, if I look into the references of the web project inside visual studio. The path of Newtonsoft.Json points to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Blend\Newtonsoft.Json.dll but Copy Local is false.
How can that be? How can we handle this conflict?
You need to add a binding redirection in your web.config (possibly merge with your existing binding redirections):
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
The redirect did not work for me until I update the Web Api to a recent version:
PM> update-package Microsoft.AspNet.WebApi.Client -Version 4.0.30506
Updating 'Microsoft.AspNet.WebApi.Client' from version '4.0.20710.0' to '4.0.30506.0' in project 'TestProject.Api'.
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
Okay, here is my fix.
Well one thing I don't know is how the Json.net reference points to the dll in the Blend folder in the first place.
I tried to re-NuGet but found it rather inconvenient because WebApi and WebGrease are all dependent on it.
So I just went ahead and deleted that reference. That of course breaks everything related.
When adding the reference back, I simply Add Reference by browsing to the dll under the /.package folder inside this project.
It works!
Pretty brutal? Just make sure we checked
.csproj
Web.Config
the property in the Reference entry in VS
Dare to try after all bases are covered.