2011-12-31 126 views
0

我對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 
+0

我認爲整個堆棧跟蹤不夠。你應該提供代碼,你如何使用ninject。 – adt 2011-12-31 11:32:00

+0

請添加更多背景!你的NInject內核是如何配置的?獲取異常時執行的代碼是什麼? – nemesv 2011-12-31 11:32:30

+0

從框架代碼中拋出的'NullReferenceException'通常表明該框架中存在一個錯誤,因爲框架不應該拋出'NullReferenceException'(因爲NRE對於告訴問題是沒有什麼幫助的)。 – Steven 2011-12-31 12:06:20

回答

2

從堆棧跟蹤我可以看到你使用的是一些Ninject 1.x.x版本。當前版本是2.2.1,從nuget中可以安裝版本3.0.0的候選版本。 Ninject 1不再被維護。

我建議更新到2.2.1或3.0.0。否則,您將不得不從github獲取源代碼並自己調試問題,並提供解決問題的pull請求。

0

我有類似的問題。在我的情況下,我使用的是Mono上的Nuget的Ninject 3.2.2.0包,必須回滾到3.2.0.0,因爲我從this ticket on the Ninject issue tracker中發現了這個包。看起來Ninject通過反射在.Net中使用非公開的API,而這在Mono中不存在。