Question

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).

Was it helpful?

Solution

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>

OTHER TIPS

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>

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top