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
Okay, so this is how to fix:
Ninject.Web
package completely. This package is no longer required as it is now integrated into Ninject.Web.Common
(well, version v3.3+ anyway)Ninject
, Ninject.Web.Common
and Ninject.Web.Common.WebHost
. These should now upgrade okay. For me, they are both v3.3.1.App_Start\Ninject.Web.Common.cs
will have been added. This is just a rename of the existing App_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 the OnePerRequestModule
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's Start()
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 to Ninject.Web.Common.WebHost
.
You can also remove the file App_Start\NinjectWeb.cs
for the same reason (registering NinjectHttpModule
)
If OnePerRequestHttpModule
doesn't resolve in App_Start\Ninject.Web.Common.cs
then add the following using statement to the file using Ninject.Web.Common.WebHost;
(I think this is a missing reference in v3.3.1 of the package.
Hope this helps others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With