ninject/ninject — Issue #39: Mono - Using providers cause NullReferenceException
Author: kappy
Created: 2011-10-10 21:38:03+00:00
State: open

```C#
Kernel.Bind().ToProvider();
```

Causes a NullReferenceException on Mono. On Windows works fine. I'm using Ninject 2.2.1.0 for mono (2.2.1.4 from nuget throws same expcetion) and Mono 2.10.5.

IConfig, DynamicConfig and ConfigProvider are simple classes. I can post them here if you want.

stacktrace:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object
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+c__AnonStorey29.<>m__4A (IInjectionHeuristic h) [0x00000] in :0
at System.Linq.Enumerable.Any[IInjectionHeuristic] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in :0
at Ninject.Selection.Selector.m__47 (System.Reflection.PropertyInfo p) [0x00000] in :0
at System.Linq.Enumerable+c__Iterator1D`1[System.Reflection.PropertyInfo].MoveNext () [0x00000] in :0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in :0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddRange (IEnumerable`1 collection) [0x00000] in :0
at Ninject.Selection.Selector.SelectPropertiesForInjection (System.Type type) [0x00000] in :0
at Ninject.Planning.Strategies.PropertyReflectionStrategy.Execute (IPlan plan) [0x00000] in :0
at Ninject.Planning.Planner+c__AnonStorey28.<>m__44 (IPlanningStrategy s) [0x00000] in :0
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable`1 series, System.Action`1 action) [0x00000] in :0
at Ninject.Planning.Planner.GetPlan (System.Type type) [0x00000] in :0
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in :0
at Ninject.Activation.Context.Resolve () [0x00000] in :0
at Ninject.KernelBase.m__55 (IContext context) [0x00000] in :0
at System.Linq.Enumerable+c__Iterator10`2[Ninject.Activation.IContext,System.Object].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator0`1[NInjectTest2.ConfigProvider].MoveNext () [0x00000] in :0
at System.Linq.Enumerable.Single[ConfigProvider] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in :0
at System.Linq.Enumerable.Single[ConfigProvider] (IEnumerable`1 source) [0x00000] in :0
at Ninject.ResolutionExtensions.Get[ConfigProvider] (IResolutionRoot root, Ninject.Parameters.IParameter[] parameters) [0x00000] in :0
at Ninject.Planning.Bindings.BindingBuilder`1[NInjectTest2.IConfig].m__33[ConfigProvider] (IContext ctx) [0x00000] in :0
at Ninject.Planning.Bindings.Binding.GetProvider (IContext context) [0x00000] in :0
at Ninject.Activation.Context.GetProvider () [0x00000] in :0
at Ninject.Activation.Context.Resolve () [0x00000] in :0
at Ninject.KernelBase.m__55 (IContext context) [0x00000] in :0
at System.Linq.Enumerable+c__Iterator10`2[Ninject.Activation.IContext,System.Object].MoveNext () [0x00000] in :0
at System.Linq.Enumerable.Single[Object] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in :0
at System.Linq.Enumerable.SingleOrDefault[Object] (IEnumerable`1 source) [0x00000] in :0
at Ninject.Planning.Targets.Target`1[System.Reflection.ParameterInfo].GetValue (System.Type service, IContext parent) [0x00000] in :0
at Ninject.Planning.Targets.Target`1[System.Reflection.ParameterInfo].ResolveWithin (IContext parent) [0x00000] in :0
at Ninject.Activation.Providers.StandardProvider.GetValue (IContext context, ITarget target) [0x00000] in :0
at Ninject.Activation.Providers.StandardProvider+c__AnonStorey3.<>m__B (ITarget target) [0x00000] in :0
at System.Linq.Enumerable+c__Iterator10`2[Ninject.Planning.Targets.ITarget,System.Object].MoveNext () [0x00000] in :0
at System.Collections.Generic.List`1[System.Object].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in :0
at System.Collections.Generic.List`1[System.Object]..ctor (IEnumerable`1 collection) [0x00000] in :0
at System.Linq.Enumerable.ToArray[Object] (IEnumerable`1 source) [0x00000] in :0
at Ninject.Activation.Providers.StandardProvider.Create (IContext context) [0x00000] in :0
at Ninject.Activation.Context.Resolve () [0x00000] in :0
at Ninject.KernelBase.m__55 (IContext context) [0x00000] in :0
at System.Linq.Enumerable+c__Iterator10`2[Ninject.Activation.IContext,System.Object].MoveNext () [0x00000] in :0
at System.Linq.Enumerable+c__Iterator0`1[NInjectTest2.Engine].MoveNext () [0x00000] in :0
at System.Linq.Enumerable.Single[Engine] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in :0
at System.Linq.Enumerable.Single[Engine] (IEnumerable`1 source) [0x00000] in :0
at Ninject.ResolutionExtensions.Get[Engine] (IResolutionRoot root, Ninject.Parameters.IParameter[] parameters) [0x00000] in :0
at NInjectTest2.Program.Main (System.String[] args) [0x00000] in :0