FileLoadException after NuGet update for System.Web.Http

本文关键字:System Web Http for update after NuGet FileLoadException | 更新日期: 2023-09-27 18:37:11

我刚刚从 NuGet 更新了已安装的项目,并在运行时收到以下未经处理的异常:

无法加载文件或程序集"System.Web.Http,版本=4.0.0.0, 区域性=中性,公钥令牌=31bf3856ad364e35'或其之一 依赖。找到的程序集的清单定义没有 匹配程序集引用。(HRESULT的例外:0x80131040)

异常是从NinjectWebCommon引发的。引导程序。初始化(创建内核);代码行是罪犯。

 public static void Start()
 {
     DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule));
     DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule));
     bootstrapper.Initialize(CreateKernel);
 }

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

有没有人遇到过这个问题并解决了它?

编辑

似乎有问题的代码在引导程序内部。初始化() 方法:

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;
}

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

FileLoadException after NuGet update for System.Web.Http

听起来您正在使用没有程序集绑定重定向的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>