Cannot upgrade Ninject to latest version in Nuget

后端 未结 1 1500
粉色の甜心
粉色の甜心 2021-01-18 11:58

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 r

相关标签:
1条回答
  • 2021-01-18 12:49

    Okay, so this is how to fix:

    1. Remove the Ninject.Web package completely. This package is no longer required as it is now integrated into Ninject.Web.Common (well, version v3.3+ anyway)
    2. Update the packages Ninject, Ninject.Web.Common and Ninject.Web.Common.WebHost. These should now upgrade okay. For me, they are both v3.3.1.
    3. 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 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.
    4. 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.

    5. You can also remove the file App_Start\NinjectWeb.cs for the same reason (registering NinjectHttpModule)

    6. 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.

    0 讨论(0)
提交回复
热议问题