ambiguity in package references version

Viewed 8693

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?

7 Answers

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>

In my case, it was trying to find Ninject 3.3.3.0 (and I had installed v3.3.4)

I checked project file (.csproj), web.config and packages.config, and they were all fine.

  • I uninstalled all Ninject NuGet packages from all my projects.
  • Then went to "Manage NuGet packages for Solution" and reinstalled all Ninject packages for all projects from there.

I know it seems silly ... but it fixed it for me!

You will need to add the following node to the web.config file at configuration > runtime > assemblyBinding:

<dependentAssembly>
    <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.4.0" newVersion="3.3.4.0" />
</dependentAssembly>
<dependentAssembly>
    <assemblyIdentity name="Ninject.Web.Common" publicKeyToken="c7192dc5380945e7" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-3.3.2.0" newVersion="3.3.2.0" />
</dependentAssembly>

Ninject & entity framework web.config changes

Because I am running Ninject inside a Window service I needed to install the ServiceName.exe.Config file so that the app.config information gets properly loaded when my service starts.

<configuration>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
          <assemblyIdentity name="Ninject" publicKeyToken="c7192dc5380945e7" culture="neutral" />
        <bindingRedirect oldVersion="3.3.3.0" newVersion="3.3.4.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

This worked for me:

Install-Package Ninject.Web.Common.WebHost -Version 3.3.1

Run the above command in nuget package manager console.

What works for me is to delete all files in bin folder of the solution.

Related