C# – Could not load file or assembly ‘Ninject version 4.0.0.0

.net-assemblycninjectnugetversion control

There is a problem with assembly reference, guess occurred when updating nuget packages.

I start from a project which has no dependency to most dependencies(topological sort) reinstalled all nuget packages and increase version in nuspec file and all packages.config files referenced to Ninject 3.2.2.0

<package id="Ninject" version="3.2.2.0" targetFramework="net462" />
<package id="Ninject.Extensions.Conventions" version="3.2.0.0" targetFramework="net462" />

but doesn't work.

still getting error when running unit test, seems an assembly referenced to other version of Ninject

unit test fails:

Message: System.IO.FileLoadException : Could not load file or assembly 'Ninject, Version=4.0.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)
—- System.IO.FileLoadException : Could not load file or assembly 'Ninject, Version=3.2.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)

how to get more informations about this(who's calling version 4.0.0.0 or 3.2.0.0) or fix this issue?

Thanks in advance.

Best Answer

I had the same problem, I upgraded my project to 4.6.2 from 4.5 which used Ninject version 3.2.2.0, and I got the same error message.

What helped me was that I upgraded the Ninject package to the latest version (3.3.4) and Ninject.Web.Common (3.3.2).

Warning! When I did so, my NinjectWebCommon.cs file was re-generated and I lost all dependency injection settings, but once I restored it from source control, everything was fine.