ThatRendle/Simple.Web

Ninject Mono - Object Reference Not Set

Closed this issue · 2 comments

Seems the ActivationBlock in NinjectContainer (although not null) gives a Object Reference Not Set.

HandlerBuilderFactory

I'm still not 100% sure if this is an issue in NinjectContainerScope or Ninject itself but am happy the 'hidden complexity' is HandlerFactoryBuilder is OK (nb: v3 is supposed to be Mono 2/4 compatible) :-

handlerBlock = ".Block(Simple.Web.Ninject.Tests.TestHandler $var1) {\r\n    $var1 = .Call $var2.Get();\r\n    .If (\r\n        .Call $var3.ContainsKey(\"IsDisposed\")\r\n    ) {\r\n        .Try {\r\n            $var1.IsDisposed = (System.Boolean).Call Simple.Web.CodeGeneration.PropertySetterBuilder.SafeConvert(\r\n                ($var3.Item[\"IsDisposed\"])[0],\r\n                .Constant<System.RuntimeType>(System.Boolean))\r\n        } .Catch (System.Exception) {\r\n            $var1.IsDisposed = .Default(System.Boolean)\r\n        }\r\n    } .Else {\r\n        .Default(System.Void)\r\n    };\r\n    .If (\r\n        .Call $var3.ContainsKey(\"TestProperty\")\r\n    ) {\r\n        .Try {\r\n            $var1.TestProperty = (System.String).Call Simple.Web.CodeGeneration.PropertySetterBuilder.SafeConvert(\r\n                ($var3.Item[\"TestProperty\"])[0],\r\n                .Constant<System.RuntimeType>(System.String))\r\n        } .Catch (System.Exception) {\r\n            $var1.TestProperty = .Default(System.String)\r\n        }\r\n    } .Else {\r\n        .Default(System.Void)\r\n    };\r\n    $var1\r\n}"

scopeBlock =     
    [0]: {(Param_0 = value(Simple.Web.Ninject.NinjectContainer).BeginScope())}
    [1]: {(Param_0 = {var Param_1; ... })}
    [2]: {Param_0}
    [3]: {(Param_0 = Create(Param_1, Param_2))}
    [4]: {Param_0}

Unit test error

xunit.dll: Version 1.9.0.1566
Test assembly: ./test/Simple.Web.Ninject.Tests.dll

Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.CreatesInstanceOfType [FAIL]
System.NullReferenceException : Object reference not set to an instance of an object
Stack Trace:
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.getParentDefinitionMethodInfo () [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.MethodInfo method, BindingFlags flags) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in :0 
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in :0 
at Ninject.Selection.Selector+<>cDisplayClass3.b2 (IInjectionHeuristic h) [0x00000] in :0 
at System.Linq.Enumerable.AnyIInjectionHeuristic [0x00000] in :0 
at Ninject.Selection.Selector.b1 (System.Reflection.PropertyInfo p) [0x00000] in :0 
at System.Linq.Enumerable+cIterator351[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable1 enumerable) [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddRange (IEnumerable1 collection) [0x00000] in <filename unknown>:0 
at Ninject.Selection.Selector.SelectPropertiesForInjection (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute (IPlan plan) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner+<>c__DisplayClass1.<CreateNewPlan>b__0 (IPlanningStrategy s) [0x00000] in <filename unknown>:0 
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable1 series, System.Action1 action) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.CreateNewPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.GetPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Context.Resolve () [0x00000] in <filename unknown>:0 
at Ninject.KernelBase+<>c__DisplayClass10.<Resolve>b__c (IBinding binding) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator272[Ninject.Planning.Bindings.IBinding,System.Object].MoveNext () [0x00000] in :0 
at System.Linq.Enumerable+c_Iterator171[Simple.Web.Ninject.Tests.TestHandler].MoveNext () [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.Single[TestHandler] (IEnumerable1 source, System.Func2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.SingleOrDefault[TestHandler] (IEnumerable1 source) [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Simple.Web.Ninject.NinjectContainerScope.GetTestHandler [0x00000] in :0 
at (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,System.Collections.Generic.IDictionary`2)
at Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.CreatesInstanceOfType () [0x00000] in :0 
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.DisposesInstances [FAIL]
System.NullReferenceException : Object reference not set to an instance of an object
Stack Trace:
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.getParentDefinitionMethodInfo () [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.MethodInfo method, BindingFlags flags) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in :0 
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in :0 
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in :0 
at Ninject.Selection.Selector+<>cDisplayClass3.b2 (IInjectionHeuristic h) [0x00000] in :0 
at System.Linq.Enumerable.AnyIInjectionHeuristic [0x00000] in :0 
at Ninject.Selection.Selector.b1 (System.Reflection.PropertyInfo p) [0x00000] in :0 
at System.Linq.Enumerable+cIterator351[System.Reflection.PropertyInfo].MoveNext () [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable1 enumerable) [0x00000] in <filename unknown>:0 
at System.Collections.Generic.List1[System.Reflection.PropertyInfo].AddRange (IEnumerable1 collection) [0x00000] in <filename unknown>:0 
at Ninject.Selection.Selector.SelectPropertiesForInjection (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute (IPlan plan) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner+<>c__DisplayClass1.<CreateNewPlan>b__0 (IPlanningStrategy s) [0x00000] in <filename unknown>:0 
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable1 series, System.Action1 action) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.CreateNewPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Planning.Planner.GetPlan (System.Type type) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in <filename unknown>:0 
at Ninject.Activation.Context.Resolve () [0x00000] in <filename unknown>:0 
at Ninject.KernelBase+<>c__DisplayClass10.<Resolve>b__c (IBinding binding) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator272[Ninject.Planning.Bindings.IBinding,System.Object].MoveNext () [0x00000] in :0 
at System.Linq.Enumerable+c_Iterator171[Simple.Web.Ninject.Tests.TestHandler].MoveNext () [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.Single[TestHandler] (IEnumerable1 source, System.Func2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0 
at System.Linq.Enumerable.SingleOrDefault[TestHandler] (IEnumerable1 source) [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Ninject.ResolutionExtensions.TryGetTestHandler [0x00000] in :0 
at Simple.Web.Ninject.NinjectContainerScope.GetTestHandler [0x00000] in :0 
at (wrapper dynamic-method) object:lambda_method (System.Runtime.CompilerServices.Closure,System.Collections.Generic.IDictionary`2)
at Simple.Web.Ninject.Tests.HandlerFactoryBuilderTests.DisposesInstances () [0x00000] in :0 
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in :0

2 total, 2 failed, 0 skipped, took 0.609 seconds

Update; posted message to Ninject google group with mono runtime trace.

Fixed by using Mono-specific version of Ninject with conditional reference. In upcoming pull-request.