问题
I have a ASP.NET WebForms application that uses some Ninject packages, but I am stuck at a certain version. When I try to upgrade to the latest version, I get "Unable to resolve dependencies" issues.
The packages in question are:
Package InstalledVer LatestVer
------------------------------------------------------
Ninject v3.2.2 v3.3.4
Ninject.Web v3.2.1 ✔ v3.2.1
Ninject.Web.Common v3.2.3 v3.3.1
Ninject.Web.Common.WebHost v3.2.3 v3.3.1
If I try updating Ninject
, I get:
Unable to resolve dependencies. 'Ninject 3.3.4' is not compatible with 'Ninject.Web 3.2.1 constraint: Ninject (>= 3.2.0 && < 3.3.0)'
but Ninject.Web
is already at the latest version!
Should I change the Dependency behaviour of Ninject.Web
or would this be unsafe? If I do, what should I change the Dependency behavior to?
Thanks
回答1:
Okay, so this is how to fix:
- Remove the
Ninject.Web
package completely. This package is no longer required as it is now integrated intoNinject.Web.Common
(well, version v3.3+ anyway) - Update the packages
Ninject
,Ninject.Web.Common
andNinject.Web.Common.WebHost
. These should now upgrade okay. For me, they are both v3.3.1. - As part of the package upgrade a new file
App_Start\Ninject.Web.Common.cs
will have been added. This is just a rename of the existingApp_Start\NinjectWeb.Common.cs
so either [a] delete the new file or [b] migrate over your Ninject module registrations and remove the old file. In
web.config
, you should now remove theOnePerRequestModule
module:<system.webServer> <modules runAllManagedModulesForAllRequests="true"> <add name="OnePerRequestModule" type="Ninject.Web.Common.OnePerRequestHttpModule" /> </modules> </system.webServer>
This is because this module, is registered dynamically on loadup in the
App_Start\Ninject.Web.Common.cs
file'sStart()
method:public static void Start() { DynamicModuleUtility.RegisterModule(typeof(OnePerRequestHttpModule)); DynamicModuleUtility.RegisterModule(typeof(NinjectHttpModule)); bootstrapper.Initialize(CreateKernel); }
If you don't remove this entry from web.config then you can expect a type exception when launching your application, not least because as part of the version update, the class has moved from the
Ninject.Web.Common
namespace toNinject.Web.Common.WebHost
.You can also remove the file
App_Start\NinjectWeb.cs
for the same reason (registeringNinjectHttpModule
)If
OnePerRequestHttpModule
doesn't resolve inApp_Start\Ninject.Web.Common.cs
then add the following using statement to the fileusing Ninject.Web.Common.WebHost;
(I think this is a missing reference in v3.3.1 of the package.
Hope this helps others.
来源:https://stackoverflow.com/questions/52272485/cannot-upgrade-ninject-to-latest-version-in-nuget