ninject / Ninject

the ninja of .net dependency injectors
http://ninject.org/
Other
2.68k stars 530 forks source link

Assembly version mismatch when using latest version of different Ninject packages #348

Open johnjaylward opened 5 years ago

johnjaylward commented 5 years ago

See also #337, #326

Basically the problem comes down to the different packages requiring different version of the Ninject library. For my case, I was trying to bring Ninject into a Web.MVC project using the Ninject.MVC5 package. A shared library I control was updated to use Ninject version 3.3.4. However, Ninject.MVC5 includes Ninject.Web.Common.WebHost version 3.3.0 which in turn includes Ninject.Web.Common version 3.3.0 which in turn includes Ninject version 3.3.3

When loading the web project I would get the following error:

=== Pre-bind state information ===
LOG: DisplayName = Ninject, Version=3.3.3.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7
 (Fully-specified)
LOG: Appbase = file:///C:/Users/AylwardJ/source/Workspaces/Solution/Project/
LOG: Initial PrivatePath = C:\Users\AylwardJ\source\Workspaces\SolutionProject\bin
Calling assembly : Ninject.Web.Common.WebHost, Version=3.3.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\Users\AylwardJ\source\Workspaces\SolutionProject\web.config
LOG: Using host configuration file: C:\Program Files\IIS Express\config\templates\PersonalWebServer\aspnet.config
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Ninject, Version=3.3.3.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7
LOG: Attempting download of new URL file:///C:/Users/AylwardJ/AppData/Local/Temp/Temporary ASP.NET Files/root/52ccbfd2/688df273/Ninject.DLL.
LOG: Attempting download of new URL file:///C:/Users/AylwardJ/AppData/Local/Temp/Temporary ASP.NET Files/root/52ccbfd2/688df273/Ninject/Ninject.DLL.
LOG: Attempting download of new URL file:///C:/Users/AylwardJ/source/Workspaces/Solution/Project/bin/Ninject.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Build Number
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

So next, I tried to update to update the internal dependency of Ninject.Web.Common.Webhost which also updates Ninject.Web.Common. However that still failed because Ninject 3.3.3 is still pulled in, not 3.3.4.

Downgrading my library that was initially pulling in Ninject 3.3.4 to instead use Ninject 3.3.3 was the only solution that works.

Is there any way you can either make the assembly versions more loosely coupled, or update the children projects to use the latest version of ninject?

dlebee commented 5 years ago

Same issue here, we have lots of child projects not updating the resource, and it since some are loaded dynamically it causes a lot of Ninject version miss match.

johnjaylward commented 5 years ago

@dlebee I switched to https://github.com/simpleinjector shortly after opening this and have been happy ever since. Simple Injector also helped me find some configuration issues in unit testing that was difficult/impossible to find with Ninject.