Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ambiguity in package references version

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 -> enter image description here

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?

like image 693
M.Khooryani Avatar asked Oct 08 '17 06:10

M.Khooryani


2 Answers

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.

like image 93
Roy B Avatar answered Oct 06 '22 02:10

Roy B


I had the exact same problem with the same versionnumbers as you had.

There's something strange going on with Ninject 3.2.2.0.

What solved this for me was to leave the 3.2.2 package installed. Leave the packages.config alone and change the app.config to 3.2.0.0. Yes. Thats right. Not to 3.2.2.0, but to 3.2.0.0. This is what the runtime exception is whining about, so I thought I'd give it a try.

So to summarize:

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>

Packages.config:

<package id="Ninject" version="3.2.2.0" targetFramework="net452" />

App.config:

<dependentAssembly>
    <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.2.0.0" newVersion="3.2.0.0" />
</dependentAssembly>
like image 32
Jon Koeter Avatar answered Oct 06 '22 02:10

Jon Koeter