【问题标题】:FileLoadException after NuGet update for System.Web.Http对 System.Web.Http 进行 NuGet 更新后的 FileLoadException
【发布时间】:2013-10-29 10:28:10
【问题描述】:

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

无法加载文件或程序集'System.Web.Http,版本=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);
 }

我假设 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;
}

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

【问题讨论】:

  • 你能解决这个问题吗?在建议的解决方案之后,我不再出现异常,但 DI 无法正常工作......

标签: c# ninject nuget


【解决方案1】:

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

【讨论】:

  • 上述内容,当添加到我的 web.config 时,删除了异常,但 WebApi 不再工作。
  • 这意味着您在应用程序中混合了程序集版本
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-02
  • 1970-01-01
  • 1970-01-01
  • 2019-01-26
  • 1970-01-01
  • 1970-01-01
  • 2019-01-12
相关资源
最近更新 更多