In a project, there are several references to Ninject library which have their version, and the unit test fails, this is the error :
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)
1- csproj file
<Reference Include="Ninject, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll</HintPath>
</Reference>
2- packages.config
<package id="Ninject" version="3.2.2.0" targetFramework="net462" />
3- app.config
<dependentAssembly>
<assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
4- references folder -> expand -> right click on Ninject -> properties
Version: 3.2.0.0
5- Manage NuGet packages -> installed ->
looks like somewhere in my project referenced to version 4.0.0.0 and 3.2.0.0 I want only reference to version 3.2.2.0.
how to do that?
what're the differences between these references?
I know this is an old post, but I think this insight will be very useful to troubleshoot issues.
In your exception, check what assembly is being loaded. That assembly is the one that is requiring the specific version of assembly it depends on and throwing the exceptions when it's the incorrect version. It is highly likely that you've downgraded the dependent assembly. Even if the nuget packages and references might be correct, what matters is the assembly inside the bin folder.
Check if all the assemblies are deleted when you clean the solution/project. if it's not, delete all that has not been deleted.
For ninject, the problem is most likely Ninject.Web.Common.WebHost that is not getting deleted when cleaning the solution/project. It is not referenced in the project directly, but copied into the bin folder.