Failed to load file or assembly "System.Web.Http.Owin"

I updated MVC5 and Web Api 2.2, I created a MVC web application. Inside this, I added an empty web API, defined as a child of my main project, all I want to do is protect my data, Routing worked fine. but there is some data that I want to get in my context, when I try to enter localhost: 34862 / api / account / test , I get an error

Here are my codes in my ApiController

[RoutePrefix("api/account")] public class AccountController : ApiController { private readonly IAccountUoW _iaUoW; public AccountController(IAccountUoW iaUoW) { _iaUoW = iaUoW; } [Route("")] [HttpGet] public string Get() { return "test"; } [Authorize] [Route("test")] [HttpGet] public async Task<IHttpActionResult> GetTourInfos() { var ctx = (OwinContext)Request.GetOwinContext(); ClaimsPrincipal user = ctx.Authentication.User; IEnumerable<Claim> claims = user.Claims; return Ok(); } } 

my links that I add from NuGet

  • Microsoft ASP.NET Web API 2.2
  • Owin
  • Microsoft.Owin
  • Microsoft.Owin.Host.SystemWeb
  • Microsoft.Owin.Security.Cookies
  • Microsoft.Owin.Security.OAuth

I also checked the links that I added from my main project to my subproject, it has the same version from my subproject

here package.config from subproject

 <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Microsoft.AspNet.WebApi" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" /> <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" /> </packages 

Here is my .config package from my main project

 <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Antlr" version="3.4.1.9004" targetFramework="net45" /> <package id="bootstrap" version="3.0.0" targetFramework="net45" /> <package id="EntityFramework" version="6.1.1" targetFramework="net45" /> <package id="jQuery" version="1.10.2" targetFramework="net45" /> <package id="jQuery.Validation" version="1.11.1" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Core" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.EntityFramework" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Identity.Owin" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.AspNet.Mvc" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.Razor" version="3.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Client" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Core" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.Owin" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.2" targetFramework="net45" /> <package id="Microsoft.AspNet.WebPages" version="3.2.2" targetFramework="net45" /> <package id="Microsoft.jQuery.Unobtrusive.Validation" version="3.2.0" targetFramework="net45" /> <package id="Microsoft.Owin" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Host.SystemWeb" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Cookies" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Facebook" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Google" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.MicrosoftAccount" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.OAuth" version="3.0.0" targetFramework="net45" /> <package id="Microsoft.Owin.Security.Twitter" version="2.1.0" targetFramework="net45" /> <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" /> <package id="Modernizr" version="2.6.2" targetFramework="net45" /> <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" /> <package id="Ninject" version="3.2.0.0" targetFramework="net45" /> <package id="Ninject.MVC5" version="3.2.1.0" targetFramework="net45" /> <package id="Ninject.Web.Common" version="3.2.0.0" targetFramework="net45" /> <package id="Ninject.Web.Common.WebHost" version="3.2.0.0" targetFramework="net45" /> <package id="Ninject.Web.WebApi" version="3.2.1.0" targetFramework="net45" /> <package id="Owin" version="1.0" targetFramework="net45" /> <package id="Respond" version="1.2.0" targetFramework="net45" /> <package id="Unity" version="3.5.1404.0" targetFramework="net45" /> <package id="WebActivatorEx" version="2.0" targetFramework="net45" /> <package id="WebGrease" version="1.5.2" targetFramework="net45" /> </packages> 

here is my mistake

Failed to load file or assembly "System.Web.Http.Owin, Version = 5.2.2.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35" or one of its dependencies. The system cannot find the specified file.

In the package manager, I also run the Microsoft.AspNet.WebApi -reinstall update package, but still there is an error, which I don’t see? anyone help me? Any answer would be appreciated in advance.

+5
source share
1 answer

The problem is that Web Api 2.2 uses version microsoft.owin 2.0.2. You can change the behavior in the web.config file.

If your version of microsoft.owin is 3.0.0, in the string "bindingRedirect" in "newVersion" set 3.0.0

 <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="3.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> 

communication

+9
source

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


All Articles