Issues after installing ninject mvc 3 in mvc 5 project

元气小坏坏 提交于 2019-12-12 13:19:22

问题


I have created new asp mvc 5 project.
Project target .NET 4.5.
I installed ninject mvc 3 nuget package. But when I run project I get this error in NinjectWebCommon.cs in CreateKernel() method:

An exception of type 'System.IO.FileLoadException' occurred in Ninject.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.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)


回答1:


You get this error because the Ninject.MVC assebly is referencing an older version of ASP.NET MVC assembly. Since it's strongly typed, you have to inform the application to use the newer assembly. That's why web.config files in the default project templates contain runtime sections like this:

<runtime>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
  </dependentAssembly>
</runtime>

You can add this to your configuration or use the newer Ninject package.




回答2:


Please make sure to include this in application webconfig file.

 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

e.g.

 <runtime>
     <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
          <bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
        </dependentAssembly>
     </assemblyBinding>
 </runtime>


来源:https://stackoverflow.com/questions/23374406/issues-after-installing-ninject-mvc-3-in-mvc-5-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!