I have created a basic ASP.NET Web Api Application inside VS Express 2013 using all of the defaults. I added a controller and it returns XML just as I want.
As soon as I install the CORS package:
Install-Package Microsoft.AspNet.WebApi.Cors -Pre
I can't even run the application anymore:
An exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll and wasn't handled before a managed/native boundary
Additional information: Could not load file or assembly 'System.Web.Http, 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)
I followed all of the instructions on this blog post: http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api which says nothing about this issue.
I tried updating Web API with:
Install-Package Microsoft.AspNet.WebApi -Pre
But still the problem persists unfortunately
In the project I am using WebApi.Hal which depends on Web.Api 5.0 and greater. Are there any breaking changes perhaps?
Absolute Minimum To Reproduce the Problem
Upgrade Web Api - fixes problem
Install-Package Microsoft.AspNet.WebApi -Pre
Can I use an old version of the CORS library that doesn't kill everything else?
Detailed Stack trace
=== Pre-bind state information ===
LOG: DisplayName = System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///C:
LOG: Initial PrivatePath = C
Calling assembly : WebApi.Hal, Version=2.2.0.18, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:
LOG: Using host configuration file: C:\
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Net.Http.Formatting, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C: Files/root/aa0e7960/9dfdb45e/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C: Files/root/aa0e7960/9dfdb45e/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL.
LOG: Attempting download of new URL file:///C:/CORSTest/CORSTest/bin/System.Net.Http.Formatting.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Minor Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
Two step to fix the problem
Add
dependentAssembly assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" dependentAssembly
to web.config
Hope it help
Tam Nguyen
The problem is due to version conflicts of System.Net.Http.Formatting as well as System.Web.Http assemblies. If you see your output window after building your code, it gives you the solution to the problem. All you have to do is add the following into your Web.config file:
<dependentAssembly><assemblyIdentity name="System.Net.Http.Formatting" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /></dependentAssembly>
<dependentAssembly><assemblyIdentity name="System.Web.Http" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" /></dependentAssembly>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With