Ninject.Web.Common throwing ActivationException tries to insert dependencies in HttpApplicationInitializationHttpModule

I'm not sure where to even start solving this, but I get an exception when trying to start an ASP.NET MVC application.

Here is the error I get:

[ActivationException: IntPtr activation error

There are no corresponding bindings, and the type is not self-switching. Activation path:

  • Including IntPtr Dependency in a Method Parameter of a Func {IKernel} Constructor
  • Including the Func {IKernel} dependency in the lazyKernel parameter of the constructor of the HttpApplicationInitializationHttpModule type
  • Request for IHttpModule

Suggestions:

  • Make sure you specify the binding for IntPtr.
  • If the binding has been defined in the module, make sure that the module is loaded into the kernel.
  • Make sure that you do not accidentally create more than one core.
  • If you use constructor arguments, make sure that the parameter name matches the name of the constructor parameter.
  • If you use automatic module loading, make sure that the search path and filters are correct.

The stack trace is as follows:

at Ninject.KernelBase.Resolve(IRequest request) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 359 at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197 at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165 at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114 at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386 at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext() at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source) at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 197 at Ninject.Planning.Targets.Target`1.ResolveWithin(IContext parent) in c:\Projects\Ninject\ninject\src\Ninject\Planning\Targets\Target.cs:line 165 at Ninject.Activation.Providers.StandardProvider.GetValue(IContext context, ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 114 at Ninject.Activation.Providers.StandardProvider.<>c__DisplayClass4.<Create>b__2(ITarget target) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96 at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext() at System.Linq.Buffer`1..ctor(IEnumerable`1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source) at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\ninject\src\Ninject\Activation\Providers\StandardProvider.cs:line 96 at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\ninject\src\Ninject\Activation\Context.cs:line 157 at Ninject.KernelBase.<>c__DisplayClass10.<Resolve>b__c(IBinding binding) in c:\Projects\Ninject\ninject\src\Ninject\KernelBase.cs:line 386 at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext() at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at Ninject.Web.Common.NinjectHttpModule.Init(HttpApplication context) in c:\Projects\Ninject\Ninject.Web.Common\src\Ninject.Web.Common\NinjectHttpModule.cs:line 41 at System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) at System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) at System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) at System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) 

This is not like the error everyone is getting (at least my Google searches didn’t display anything useful), so I guess I'm doing something weird, but I have no idea where to start debugging this.

I should mention that I use several Ninject libraries (Ninject, Ninject.Web.Common, Ninject.MVC3 and Ninject.FluentValidation), all of which are version 3.0.00-RC3. I understand that all bets are disabled if I use libraries before release, but I have a feeling that I am doing something wrong, because others do not seem to get the same error.

Any thoughts on what might be the problem or where should I start looking?

+4
source share
4 answers

I decided to delete the App_Start \ NinjectWebCommon.cs file (which was created when installing Ninject.MVC 3.0.0-rc2) and reinstall the Nuget package (rc3). The newly created NinjectWebCommon.cs file was slightly different. The problem is solved!

+5
source

You can fix this by adding these two kernel bindings:

 kernel.Bind<Func<IKernel>>().ToMethod(ctx => () => new Bootstrapper().Kernel); kernel.Bind<IHttpModule>().To<HttpApplicationInitializationHttpModule>(); 
+9
source

I had the same problem with the WebApi project that I noticed that CreateKernel in App_Start / NinjectWebCommon.cs was called twice, and the second time it worked, I fixed the deletion of two lines at the very top of this file

 [assembly: WebActivatorEx.PreApplicationStartMethod(typeof(RetailStore.App_Start.NinjectWebCommon), "Start")] [assembly: WebActivatorEx.ApplicationShutdownMethodAttribute(typeof(RetailStore.App_Start.NinjectWebCommon), "Stop")] 

And then the method was called once, and the error disappeared.

+1
source

I received the same error message, although the code has not changed from the night before. I worked on a sample code from http://www.asp.net/web-api/videos/getting-started/authorization

I lost hours ago over something stupid. I assigned my controller to [Authorize], but the next day, when I started working and tested the api, my session was no longer valid, so I assumed that it was something subtle in the code that changed.

Hope this helps someone else who is new to Ninject since I ...

What appeared in my browser was:
XML Parsing Error: no element found
Location: server-name/api/Cities/
Line Number 1, Column 1:

0
source

Source: https://habr.com/ru/post/1401272/


All Articles