3

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)

1110
  • 7,829
  • 55
  • 176
  • 334

2 Answers2

3

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.

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
  • I have created new project and install `Ninject.MVC5` and it works. But in project where I made mistake I removed all ninject files and install `Ninject.MVC5` but same error comming. What do you think what should I do to clean project somehow? I have tried to rebuild whole solutions but still same. – 1110 Apr 29 '14 at 20:38
  • @1110 Do you have to dependentAssembly entry for System.Web.Mvc in your web.config? – Ufuk Hacıoğulları Apr 29 '14 at 20:41
  • No. But I added it now and I get error: `Could not load file or assembly 'System.Web.Mvc' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)` – 1110 Apr 29 '14 at 20:42
  • @1110 What's the version of System.Web.Mvc package in your project? Look it up on packages.config file. – Ufuk Hacıoğulları Apr 29 '14 at 20:44
  • 5.0.0.0 is System.Web.Mvc version. – 1110 Apr 29 '14 at 20:45
  • @1110 Updated the configuration in my answer, try it again. – Ufuk Hacıoğulları Apr 29 '14 at 20:46
  • Yes I changed new version to 5.0.0.0 but I didn't in old version :) Thanks a lot – 1110 Apr 29 '14 at 20:48
3

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>
amighty
  • 784
  • 4
  • 12