Prevent assembly binding at runtime to old assemblies

I have a solution with three projects:

Solution.Web.Core - General Classes
Solution.Web.Mvc - MVC 4
Solution.Web.Api - Api 2 web application that supports ASP.NET 5.0 (beta-1) builds

I have WebApi configured as a child application (in IIS) of an MVC application, however I am having problems completely isolating this project.

Since Solution.Web.Core has some links to ASP.NET 4.0 assemblies, if I add a link to this project in Solution.Web.Api , at runtime I get the following exception:

Failed to 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 manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

How can I prevent this error from occurring in Solution.Web.Api so that I can reference Solution.Web.Core despite referring to older versions of ASP.NET?

Note. Since the error says " System.Net.Http.Formatting or one of its dependencies," I honestly don’t even know how to find out which particular offensive assembly (s) are.

+4
source share
2 answers

Change Web.Config in the View section of

 <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> 
+2
source

I skipped this problem just starting with MVC 5 + Web Api 2.

However, I just found this answer to a blog post that would probably work for me:

So that the MVC 4 project can play well with 5.0 beta builds (at least the CORS builds on the blog), change the web configuration 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> 

+1
source

Source: https://habr.com/ru/post/1491275/


All Articles