0

I'm developing a webApi inside my app. I have a strange issue. I tried to do this project inside an independent console application and everything runs well. My problem is when I try to load that web api inside another big application. I'm getting this error:

Could not load file or assembly 'Microsoft.Owin, Version=3.0.1.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)

This is the class where I use it:

public class Startup
{
    public void Configuration(IAppBuilder app)
    {
        app.UseCors(CorsOptions.AllowAll); //HERE IS THE PROBLEM
        HttpConfiguration configuration = new HttpConfiguration();
        configuration.Routes.MapHttpRoute(
            name: "TestApi",
            routeTemplate: "test/{controller}/{id}",
            defaults: new {id = RouteParameter.Optional}
        );
        app.UseWebApi(configuration);
    }
}

I debugged, and my problem is when I use the app.UserCors(CorsOptions.AllowAll) function. I installed Microsoft CORS package using Nuget package manager and I tried to update it but still getting this error. I searched here Can't load System.Web.Cors assembly after call to Microsoft.Owin.Cors but the solution is not working for me.

I have this app.config file:

  <runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="3.0.1" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Cors" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
  </dependentAssembly>
</assemblyBinding>

Maybe the problem is in System.Web.Cors? I'm a bit lost.

Community
  • 1
  • 1
acostela
  • 2,597
  • 3
  • 33
  • 50

1 Answers1

2

In your config you say

<dependentAssembly>
    <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
  </dependentAssembly>

that means, that you use Microsoft.Owin version 2.0.2.0 but some of your code (implementation of IAppBuilder i suppose) requres "Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

If you use NuGet, upgrade package, If not - you should download 3.0.1.0 version, update reference and change config file

Timur Lemeshko
  • 2,747
  • 5
  • 27
  • 39
  • Thank you this solved my issue. I don't know why using nuget package manager messed my app.config files. I tried installing owin through command line and now that part is well written and working. – acostela Apr 19 '16 at 13:18