ambiguity in package references version

10

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?

c#
.net
dll
nuget
.net-assembly
asked on Stack Overflow Oct 8, 2017 by M.Khooryani • edited Apr 3, 2020 by M.Khooryani

6 Answers

20

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.

answered on Stack Overflow Dec 22, 2017 by Roy B
3

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!

answered on Stack Overflow Nov 14, 2017 by Carlos R Balebona
3

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>
answered on Stack Overflow Feb 6, 2018 by Jon Koeter
0

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>
answered on Stack Overflow Jan 17, 2018 by Zamboni
0

This worked for me:

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

Run the above command in nuget package manager console.

answered on Stack Overflow May 8, 2020 by abhinav
0

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

answered on Stack Overflow May 10, 2020 by Nitin Dhiman • edited May 10, 2020 by dmkvl

User contributions licensed under CC BY-SA 3.0