在System.Web.Http的NuGet更新之后的FileLoadException

Rya*_*ars 3 c# ninject nuget

我刚从NuGet更新了已安装的项目,并在运行时获得了下面未处理的异常:

无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT异常:0x80131040)

从NinjectWebCommon抛出异常.bootstraper.Initialize(CreateKernel); 代码行是罪犯.

 public static void Start()
 {
     DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
     DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
     bootstrapper.Initialize(CreateKernel);
 }
Run Code Online (Sandbox Code Playgroud)

我假设Ninject可能依赖于旧版本的System.Web.Http,但如果我不需要,则不想回滚.

有人有这个问题并解决了吗?

编辑

似乎有问题的代码在bootstrapper.Initialize()方法中:

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;
}
Run Code Online (Sandbox Code Playgroud)

当我在现有评论下注释掉代码行时,项目运行正常.需要弄清楚如何在没有WebApiContrub.IoC.Ninject的情况下让WebApi工作......

Rem*_*oor 9

听起来像是在没有程序集绑定重定向的情况下使用Web API2

<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>
Run Code Online (Sandbox Code Playgroud)