在“新StandardKernal()”上出现“无法加载文件或程序集'Ninject.Web.Common'”错误

时间:2019-01-12 22:43:37

标签: c# asp.net ninject ninject.web.mvc

我有一个Web API asp.net项目(.net框架4.6.1)。我导入了Ninject.Web.WebApi.WebHost nuget程序包,该程序包在我的App_Start文件夹中创建了一个Ninject.Web.Common.cs文件。

当我尝试运行Web应用程序时,出现此错误:

System.IO.FileLoadException: 'Could not load file or assembly 'Ninject.Web.Common, 
Version=3.3.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7' or one of its dependencies. 
The located assembly's manifest definition does not match the assembly reference. 
(Exception from HRESULT: 0x80131040)'

这发生在Ninject.Web.Common文件的这一行:

    private static IKernel CreateKernel()
    {
        var kernel = new StandardKernel(); // happens here
        try
        {
            kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel);
            kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>();
            RegisterServices(kernel);
            return kernel;
        }
        catch
        {
            kernel.Dispose();
            throw;
        }
    }

我已经安装了这些Ninject软件包。他们所有的依赖关系似乎都很好:

  • Ninject v3.3.4
  • Ninject.Web.Common v3.3.1
  • Ninject.Web.Common.WebHost v3.3.1

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

好像我解决了这个问题。我所做的是:

  1. 我卸载了这三个依赖项
  2. 重新安装它们(相同版本)
  3. 还安装了Ninject.Web.WebApi