Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FileLoadException after installing Ninject.MVC5

I am trying to learn ASP.NET MVC with Adam Freeman's "Pro ASP.NET MVC 5" book. Unfortunately all projects using Ninject throw the same error

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)

This is exactly the same problem which was discussed in this thread,

Issues after installing ninject mvc 3 in mvc 5 project

but the offered solutions don't work for me.

I have tried target platforms 4.5 and 4.5.1, Ninject MVC3 and MVC5. I have also inserted this snippet

<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>

in the Web.config file, without any effect.

Problem must be in the Ninject MVC3 and MVC5 packages. Whenever these packages are installed, any call to Ninject.StandardKernel() throws the exception, regardless if made from the Global.asaxor the new NinjectWebCommon.cs or from any other piece of code (of course, this should not matter for this kind of exception anyway, but in this thread Error using Ninject with ASP.NET V4 it was suggested that the error might have something to do with using the Global.asax for connecting Ninject to the application).

I have run out of ideas. Can anyone help?

like image 334
Steffen Avatar asked Jan 31 '26 15:01

Steffen


1 Answers

Add to your Web.config (i.e. SportsStore.WebUI project):

  <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>

It should work with this -> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

like image 85
Adam Sierosławski Avatar answered Feb 02 '26 07:02

Adam Sierosławski



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!