Ninject 空引用异常
我对 Ninject 完全陌生,看到了一个异常,不知道该怎么办。有人可以帮忙吗:-
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Object.GetType() +0
Ninject.Core.Creation.Providers.InjectionProviderBase.GetValueFromInlineArgument(IContext context, ITarget target) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:139
Ninject.Core.Creation.Providers.InjectionProviderBase.ResolveConstructorArguments(IContext context, ConstructorInjectionDirective directive) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:109
Ninject.Core.Creation.Providers.InjectionProviderBase.CallInjectionConstructor(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:79
Ninject.Core.Creation.Providers.InjectionProviderBase.Create(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:60
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:114
Ninject.Core.Behavior.BehaviorBase.CreateInstance(IContext context, Object& instance) in \Ninject\src\Core\Behavior\BehaviorBase.cs:102
Ninject.Core.Behavior.TransientBehavior.Resolve(IContext context) in \Ninject\src\Core\Behavior\TransientBehavior.cs:55
Ninject.Core.KernelBase.ResolveInstance(Type service, IContext context, Boolean isEagerActivation) in \Ninject\src\Core\KernelBase.cs:566
Ninject.Core.KernelBase.Get(Type type, IContext context) in \Ninject\src\Core\KernelBase.cs:278
Ninject.Core.Resolution.Resolvers.StandardResolver.ResolveInstance(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\StandardResolver.cs:54
Ninject.Core.Resolution.Resolvers.ResolverBase.Resolve(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\ResolverBase.cs:80
Ninject.Core.Creation.Providers.InjectionProviderBase.ResolveConstructorArguments(IContext context, ConstructorInjectionDirective directive) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:119
Ninject.Core.Creation.Providers.InjectionProviderBase.CallInjectionConstructor(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:79
Ninject.Core.Creation.Providers.InjectionProviderBase.Create(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:60
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:114
Ninject.Core.Behavior.BehaviorBase.CreateInstance(IContext context, Object& instance) in \Ninject\src\Core\Behavior\BehaviorBase.cs:102
Ninject.Core.Behavior.TransientBehavior.Resolve(IContext context) in \Ninject\src\Core\Behavior\TransientBehavior.cs:55
Ninject.Core.KernelBase.ResolveInstance(Type service, IContext context, Boolean isEagerActivation) in \Ninject\src\Core\KernelBase.cs:566
Ninject.Core.KernelBase.Get(Type type, IContext context) in \Ninject\src\Core\KernelBase.cs:278
Ninject.Core.Resolution.Resolvers.StandardResolver.ResolveInstance(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\StandardResolver.cs:54
Ninject.Core.Resolution.Resolvers.ResolverBase.Resolve(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\ResolverBase.cs:80
Ninject.Core.Activation.Strategies.FieldInjectionStrategy.Initialize(IContext context, Object& instance) in \Ninject\src\Core\Activation\Strategies\FieldInjectionStrategy.cs:59
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:130
Ninject.Core.KernelBase.InjectExistingObject(Object instance) in \Ninject\src\Core\KernelBase.cs:599
Ninject.Core.KernelBase.Inject(Object instance) in \Ninject\src\Core\KernelBase.cs:288
Ninject.Framework.Web.KernelContainer.Inject(Object instance) in \Ninject\src\Framework\Web\KernelContainer.cs:69
Ninject.Framework.Web.UserControlBase.RequestActivation() in \Ninject\src\Framework\Web\UserControlBase.cs:41
Ninject.Framework.Web.UserControlBase.OnInit(EventArgs e) in \Ninject\src\Framework\Web\UserControlBase.cs:33
System.Web.UI.Control.InitRecursive(Control namingContainer) +143
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1477
I am totally new to Ninject and am seeing an exception and dont know what to do. Can someone please help:-
Object reference not set to an instance of an object.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Object.GetType() +0
Ninject.Core.Creation.Providers.InjectionProviderBase.GetValueFromInlineArgument(IContext context, ITarget target) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:139
Ninject.Core.Creation.Providers.InjectionProviderBase.ResolveConstructorArguments(IContext context, ConstructorInjectionDirective directive) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:109
Ninject.Core.Creation.Providers.InjectionProviderBase.CallInjectionConstructor(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:79
Ninject.Core.Creation.Providers.InjectionProviderBase.Create(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:60
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:114
Ninject.Core.Behavior.BehaviorBase.CreateInstance(IContext context, Object& instance) in \Ninject\src\Core\Behavior\BehaviorBase.cs:102
Ninject.Core.Behavior.TransientBehavior.Resolve(IContext context) in \Ninject\src\Core\Behavior\TransientBehavior.cs:55
Ninject.Core.KernelBase.ResolveInstance(Type service, IContext context, Boolean isEagerActivation) in \Ninject\src\Core\KernelBase.cs:566
Ninject.Core.KernelBase.Get(Type type, IContext context) in \Ninject\src\Core\KernelBase.cs:278
Ninject.Core.Resolution.Resolvers.StandardResolver.ResolveInstance(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\StandardResolver.cs:54
Ninject.Core.Resolution.Resolvers.ResolverBase.Resolve(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\ResolverBase.cs:80
Ninject.Core.Creation.Providers.InjectionProviderBase.ResolveConstructorArguments(IContext context, ConstructorInjectionDirective directive) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:119
Ninject.Core.Creation.Providers.InjectionProviderBase.CallInjectionConstructor(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:79
Ninject.Core.Creation.Providers.InjectionProviderBase.Create(IContext context) in \Ninject\src\Core\Creation\Providers\InjectionProviderBase.cs:60
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:114
Ninject.Core.Behavior.BehaviorBase.CreateInstance(IContext context, Object& instance) in \Ninject\src\Core\Behavior\BehaviorBase.cs:102
Ninject.Core.Behavior.TransientBehavior.Resolve(IContext context) in \Ninject\src\Core\Behavior\TransientBehavior.cs:55
Ninject.Core.KernelBase.ResolveInstance(Type service, IContext context, Boolean isEagerActivation) in \Ninject\src\Core\KernelBase.cs:566
Ninject.Core.KernelBase.Get(Type type, IContext context) in \Ninject\src\Core\KernelBase.cs:278
Ninject.Core.Resolution.Resolvers.StandardResolver.ResolveInstance(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\StandardResolver.cs:54
Ninject.Core.Resolution.Resolvers.ResolverBase.Resolve(IContext outerContext, IContext innerContext) in \Ninject\src\Core\Resolution\Resolvers\ResolverBase.cs:80
Ninject.Core.Activation.Strategies.FieldInjectionStrategy.Initialize(IContext context, Object& instance) in \Ninject\src\Core\Activation\Strategies\FieldInjectionStrategy.cs:59
Ninject.Core.Activation.ActivatorBase.Create(IContext context, Object& instance) in \Ninject\src\Core\Activation\ActivatorBase.cs:130
Ninject.Core.KernelBase.InjectExistingObject(Object instance) in \Ninject\src\Core\KernelBase.cs:599
Ninject.Core.KernelBase.Inject(Object instance) in \Ninject\src\Core\KernelBase.cs:288
Ninject.Framework.Web.KernelContainer.Inject(Object instance) in \Ninject\src\Framework\Web\KernelContainer.cs:69
Ninject.Framework.Web.UserControlBase.RequestActivation() in \Ninject\src\Framework\Web\UserControlBase.cs:41
Ninject.Framework.Web.UserControlBase.OnInit(EventArgs e) in \Ninject\src\Framework\Web\UserControlBase.cs:33
System.Web.UI.Control.InitRecursive(Control namingContainer) +143
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Control.InitRecursive(Control namingContainer) +391
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1477
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有类似的问题。就我而言,我在 Mono 上使用 Nuget 的 Ninject 3.2.2.0 包,并且必须回滚到 3.2.0.0,正如我从 Ninject 问题跟踪器上的此票。看起来 Ninject 通过反射使用了 .Net 中未发布的 API,而 Mono 中不存在这一点。
I had a similar issue. In my case I was using the Ninject 3.2.2.0 package from Nuget on Mono and had to roll back to 3.2.0.0, as I found out from this ticket on the Ninject issue tracker. It looks like Ninject makes use of a non-published API in .Net by reflection, and this doesn't exist in Mono.
从堆栈跟踪中我可以看到您正在使用一些 Ninject 1.xx 版本。当前版本是 2.2.1,您可以从 nuget 安装 3.0.0 版本的候选版本。 Ninject 1 不再维护。
我建议更新到 2.2.1 或 3.0.0。否则,您将必须从 github 获取源代码并自行调试问题并提供拉取请求来解决问题。
From the stacktrace I can see that you are using some Ninject 1.x.x version. The current release is 2.2.1 and from nuget you can install a release candidate for version 3.0.0. Ninject 1 is not maintained anymore.
I recommend updating either to 2.2.1 or 3.0.0. Otherwise you will have to get the source code from github and debug the problem yourself and provide a pull request to fix the problem.