Could not load file or assembly Exception from HRESULT: 0x80131040 - asp.net

I created my first MVC 4 project and it works perfectly on local server. But when I publish it on to local folder and upload the folder contents to hosting server. I try to run it and I get this error:
Could not load file or assembly 'DotNetOpenAuth.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246' or one of its dependencies. The system cannot find the file specified.
Can any one help me please?
Web.config:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>
</assemblyBinding>
P.S The same project in Web Forms works on hosting server.

Finally found the answer!!
Go to References --> right cilck on dll file that causing the problem --> select the properties --> check the version --> match the version in properties to web config
<dependentAssembly>
<assemblyIdentity name="YourDllFile" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-YourDllFileVersion" newVersion="YourDllFileVersion" />
</dependentAssembly>

What worked for me immediately was:
I located bin folder (picture below shows).
moved all dll in other folder for safety.
then rebuild ed the project.
after solved the issue, deleted old dll files.

If your solution contains two projects interacting with each other and both using one same reference, And if version of respective reference is different in both projects; Then also such errors occurred. Keep updating all references to latest one.

I had the same issue the NuGet package version was not the same a the one on the references in the project. I had to change the version on the config to match the one in the references from the project. Go to References --> right-click on dll file that causing the problem --> select the properties --> check the version --> match the version in properties to the web config. This should fix the problem.

Add following dll files to bin folder:
DotNetOpenAuth.AspNet.dll
DotNetOpenAuth.Core.dll
DotNetOpenAuth.OAuth.Consumer.dll
DotNetOpenAuth.OAuth.dll
DotNetOpenAuth.OpenId.dll
DotNetOpenAuth.OpenId.RelyingParty.dll
If you will not need them, delete dependentAssemblies from config named 'DotNetOpenAuth.Core' etc..

Try this:
Edit the *.pubxml file in the PublishProfiles folder
set DeleteExistingFiles true
update all nugget packages, rebuild, republish and voila, issue resolved!
...worked for me when I had the same problem.

Check if the project having HRESULT: 0x80131040 error is being used/referenced by any project. If yes, kindly check if these project have similar .dll being referenced and the version is the same. If they're are not of same version number, then it is causing the said error.

I have issue with itextsharp and itextsharp.xmlworker dlls for exception-from-hresult-0x80131040 so I have removed those both dlls from references and downloaded new dlls directly from nuget packages, which resolved my issue.
May be this method can be useful to resolved the issue to other people.

I had the same problem and none of the above solved it.
Web.config was like:
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0" />
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.9.0" newVersion="5.2.9.0" />
</dependentAssembly>
I added missing dependentAssembly tags and the problem solved. Probably it happened while solving a conflict. This might help someone else's problem.

Related

How Remove old dll in visual studio?

I removed old version Newtonsoft.Json and add new verion . when run program display this error in package.config
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
and in web.config
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
How I can remove completely old verion in visual studio ?
See if there is some remnant in your project.
In the Solution Explorer, right-click on the project and chose "Unload Project". Right-click again and chose "Edit...". Now you see an Xml for your project setup. See if it is calling the older version.
Try this may it help you
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="7.0.0.1" />
</dependentAssembly>
Change newVersion into 7.0.0.1

Upgrade newtonsoft.json breaks DNN 9.1 persona bar

I'm trying to integrate SendGrid into my app and it has a dependency on newtonsoft.json.9.0.1. DNN9 ships with newtonsoft.json.7.0.0. However, if I add the binding redirect bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="9.0.1" the site loads, but the persona bar is broken.
I'm completely blocked on this. How do I upgrade newtonsoft?
Try add to webconfig code:
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>

How do I transform replace a dependentAssembly in web config?

So I'm trying to replace a dependentAssembly when someone adds my nuget package to their code.
The assembly I want to change is:
<dependentAssembly>
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
Therefor I use this xml file and help from: Web.config transforms - the missing manual
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(./_defaultNamespace:assemblyIdentity/#name:'Common.Logging.Core')">
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="2.2.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
But I'm getting the error: An error occurred while applying transformation to 'web.config' in project: 'blabla' has an invalid qualified name.
In noticed when I change "Replace" to "Remove" it is removing the complete dependentAssembly but somehow afterwards it adds the same dependentAssembly to the web.config again. Maybe because Common.Logging.Core dependency get's added after the web.config transform?
And maybe is this the reason that the Replace isn't working?
Try this:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<!-- first completely remove the parent element -->
<dependentAssembly xdt:Transform="RemoveAll"
xdt:Locator="Condition(starts-with(./_defaultNamespace:assemblyIdentity/#name,'Microsoft.Diagnostics.Tracing.EventSource'))">
</dependentAssembly>
<!-- then add the new block -->
<dependentAssembly xdt:Transform="Insert">
<assemblyIdentity name="Microsoft.Diagnostics.Tracing.EventSource" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.1.16.0" newVersion="1.1.16.0 " />
</dependentAssembly>
</assemblyBinding>
</runtime>
The XML below applies a binding redirect to assemble Common.Logging.Core.
It contains two transform operations.
The first one ,InsertIfMissing, inserts a new entry if the assembly entry doesn’t exist, and the second one, Replace, replaces it in case the existing redirect already exist.
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1">
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly xdt:Transform="InsertIfMissing" xdt:Locator="Condition(asmv1:assemblyIdentity/#name='Common.Logging.Core')">
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
</dependentAssembly>
<dependentAssembly xdt:Transform="Replace" xdt:Locator="Condition(asmv1:assemblyIdentity/#name='Common.Logging.Core')">
<assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" xmlns="urn:schemas-microsoft-com:asm.v1"/>
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" xmlns="urn:schemas-microsoft-com:asm.v1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Pay attention at the namespace asmv1 added to the configuration element. It is needed for this to work.
NB: I wanted to avoid adding assemblyIdentity and bindingRedirect elements in the InsertIfMissing transform but couldn’t make it work. Let me know if you know how.

Prevent runtime assembly binding to older assemblies

I have a solution with 3 projects:
Solution.Web.Core - Common classes
Solution.Web.Mvc - MVC 4
Solution.Web.Api - Web Api 2 aka running ASP.NET 5.0 (beta-1) assemblies
I have the WebApi set up as a child application (in IIS) of the MVC application, however, I'm having trouble achieving full isolation of this project.
Because Solution.Web.Core has some references to ASP.NET 4.0 assemblies, if I add a reference to this project in Solution.Web.Api I get the following exception at runtime:
Could not load file or assembly 'System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
How can I prevent this error occurring in Solution.Web.Api so that I can reference Solution.Web.Core despite it referencing older assembly versions of ASP.NET?
Note: Since the error says "System.Net.Http.Formatting or one of its dependencies" I'm honestly not even sure how to find out which is the exact offending assembly(s).
Change the Web.Config of the View section from
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, **Version=5.0.0.0**, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
to
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, **Version=5.2.3.0**, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
I got past this issue by just starting over with MVC 5 + Web Api 2.
However, just found this blog post answer which seems like it probably would've worked for me:
To allow an MVC 4 project to play nice with 5.0 beta assemblies (at least the CORS assemblies in the blog post) change web config to the following:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:bcl="urn:schemas-microsoft-com:bcl">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
</dependentAssembly>

Reuse shared project for MVC3 and MVC4 Solutions

we have web applications using MVC3 which all share a library with HtmlHelper Extensions.
Is there a way, to make this shared library which has to reference MVC Assemblies also work with MVC4 Applications without converting the one's existing and without duplicating the shared library?
I Tried setting the MVC references on the shared library to SpecificVersion=false, but then it switches to MVC4 and the MVC3 projects can't use it anymore.
Whenever I try to use MVC3 and MVC4 assemblies side by side, I get an unhandled win32 exception.
Any ideas how to solve this, or is the only way to go either full MVC4 or stay at MVC3? Thanks
You could use a binding redirect in the web.config of your ASP.NET MVC 4 application:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Now you could reference the assembly containing your custom helpers (and which in turn depends on ASP.NET MVC 3) in your ASP.NET MVC 4 application.

Resources