Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not load System.Web.Cors in Owin Startup.cs

I have a .Net 4.5.1 application using Web API 2 and running in my local Azure Emulator. I have some OWIN components installed and in my Startup.cs file within the Configuration(IAppBuilder app) function I have the following code block and the last line causes an exception:

HttpConfiguration httpConfiguration = new HttpConfiguration();
WebApiConfig.Register(httpConfiguration);
app.UseWebApi(httpConfiguration);
app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

This line is causing an exception "Could not load file or assembly 'System.Web.Cors, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies."

I'm having trouble figuring out why NuGet didnt' install this if it is a dependency. Additionally I'm not able to find a corresponding dll already installed to add a reference myself, nor the correct NuGet package to install to provide said dll.

Has anyone experienced a similar issue? If so, perhaps you could point me in the right direction.

like image 237
Devon Holcombe Avatar asked Sep 22 '14 17:09

Devon Holcombe


2 Answers

This is surely coming cause of your DLL version is different OR DLL is missing on that environment.

Few steps you require to check:

  • Cors DLL should be there in your BIN directory [On Azure]

  • If it's there then Version of DLL deployed on server and your local both should be same. [You can check in properties]

  • If your version of Cors DLL higher on Azure server, compare to local one then you can
<dependentAssembly>
   <assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" />
   <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.1" />
</dependentAssembly>

Your new version could be your DLL version which are available into the BIN directory.

like image 167
Abhishek Gupta Avatar answered Nov 14 '22 03:11

Abhishek Gupta


Have you tried Microsoft.Asp.Net.WebApi.Cors at nuget? https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Cors/5.2.2 It's not a dependency for the Cors package because it's for webapi and the only microsoft.owin.cors dependency is on the base microsoft.asp.net.cors (other than the owin packages).

like image 39
Mark Fitzpatrick Avatar answered Nov 14 '22 05:11

Mark Fitzpatrick