当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - FileLoadException after NuGet update for System.Web.Http

问题描述:

I just updated my installed projects from NuGet and got the unhandled exception below at runtime:

Could not load file or assembly 'System.Web.Http, Version=4.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)

The exception was thrown from NinjectWebCommon. The bootstraper.Initialize(CreateKernel); line of code was the offender.

 public static void Start()

{

DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));

DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));

bootstrapper.Initialize(CreateKernel);

}

I assume that Ninject may have a dependency on the old version of System.Web.Http, but don't want to rollback if I don't have to.

Has anyone had this problem and solved it?

EDIT

It seems as though the offending code is inside the bootstrapper.Initialize() method:

private static IKernel CreateKernel()

{

var kernel = new StandardKernel();

kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);

kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();

RegisterServices(kernel);

// Set Web API Resolver (using WebApiContrib.Ioc.Ninject)

GlobalConfiguration.Configuration.DependencyResolver = new NinjectResolver(kernel);

return kernel;

}

When I commented out the line of code under the existing comment the project ran fine. Will need to figure out how to get WebApi to work without WebApiContrub.IoC.Ninject...

网友答案:

Sounds like you are using Web API2 without assembly binding redirect

<dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
分享给朋友:
您可能感兴趣的文章:
随机阅读: