Reuse shared project for MVC3 and MVC4 Solutions - asp.net

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.

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>

Need I specify the assemblyIdentity (Web.config)?

I can create and build a new ASP.NET project and use Razor and more technologies only specifying the Razor version and 0 assemblyIdentities. I've downloaded MVC5 and my empty web project has been modified, adding assemblyIdentites in Web.config. I'm using more technologies/references and they aren't specified in Web.config with assemblyIdentity. Razor for example.
Then, will use my web the latest technologies/DLLs installed in the server if I don't specify it with assemblyIdentity? Or why VS adds this to Web.config?
This is my Web.config modified when I updated to MVC5:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
<!-- NEW
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<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" 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.2.3.0" newVersion="5.2.3.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
-->
<appSettings>
<add key="webpages:Version" value="2.0.0.0" />
</appSettings>
</configuration>
Have a look here. The post has an explanation regarding what the section of the web config file is trying to accomplish.

Could not load file or assembly Exception from HRESULT: 0x80131040

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.

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>

Resources