Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues after installing ninject mvc 3 in mvc 5 project

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)

like image 687
1110 Avatar asked Dec 09 '25 03:12

1110


2 Answers

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.

like image 129
Ufuk Hacıoğulları Avatar answered Dec 10 '25 17:12

Ufuk Hacıoğulları


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>
like image 42
amighty Avatar answered Dec 10 '25 15:12

amighty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!