でプロパティアクセサがある場合、私は他の関連する記事を探してきたが、私は何も見つかりませんでしたので、ここにNullRef例外で失敗...Ninjectはインタフェース
私は(スーパー)があり、単純なNinReferenceExcptionで失敗したNinjectテスト。理由に関する情報が見つかりません。インターフェイスにC#の単純化されたプロパティアクセサーが定義されている場合に発生します。それ以外の場合は正常です。 getを削除した場合。セット;機能は期待どおりに動作します。
私の質問は、うまくいきません。これは廃止されたフィールド注入機能に関連していますか?
全体(失敗)の例では、非常に短いです:
using System;
using Ninject;
namespace NinjectIFPropError
{
public interface IDummy
{
int Number {get;set;}
void Doit();
}
public class DummyClass : IDummy
{
public int Number {get;set;}
public void Doit()
{
Console.WriteLine("Doit");
}
}
class Program
{
public static void Main (string[] args)
{
IKernel kernel = new StandardKernel();
kernel.Bind<IDummy>().To<DummyClass>();
IDummy id = kernel.Get<IDummy>();
id.Doit();
}
}
}
私はモノ2.10.5は、Ubuntuの11.10にインストールするデフォルトを使用しています。 Ninject.orgからダウンロードした.Net 4.0用のNinjectはv2.2.1.0です。
すべての情報をいただければ幸いです。
/
私は(かなり長い)だけでなく、スタックトレースを追加しています:
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 <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in <filename unknown>:0
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in <filename unknown>:0
at Ninject.Selection.Selector+<>c__DisplayClass3.<SelectPropertiesForInjection>b__2 (IInjectionHeuristic h) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Any[IInjectionHeuristic] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at Ninject.Selection.Selector.<SelectPropertiesForInjection>b__1 (System.Reflection.PropertyInfo p) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator35`1[System.Reflection.PropertyInfo].MoveNext() [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddRange (IEnumerable`1 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__DisplayClass3.<GetPlan>b__1 (IPlanningStrategy s) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable`1 series, System.Action`1 action) [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.<Resolve>b__7 (IContext context) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator27`2[Ninject.Activation.IContext,System.Object].MoveNext() [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateCastIterator>c__Iterator17`1[NinjectIFPropError.IDummy].MoveNext() [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Single[IDummy] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Single[IDummy] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at Ninject.ResolutionExtensions.Get[IDummy] (IResolutionRoot root, Ninject.Parameters.IParameter[] parameters) [0x00000] in <filename unknown>:0
at NinjectIFPropError.Program.Main (System.String[] args) [0x00018] in /home/roger/Projects/NinjectIFPropError/Main.cs:38
[ERROR] FATAL 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 <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.GetParentDefinition (System.Reflection.PropertyInfo property) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.IsDefined (System.Reflection.PropertyInfo element, System.Type attributeType, Boolean inherit) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForMemberInfo.HasAttribute (System.Reflection.MemberInfo member, System.Type type) [0x00000] in <filename unknown>:0
at Ninject.Selection.Heuristics.StandardInjectionHeuristic.ShouldInject (System.Reflection.MemberInfo member) [0x00000] in <filename unknown>:0
at Ninject.Selection.Selector+<>c__DisplayClass3.<SelectPropertiesForInjection>b__2 (IInjectionHeuristic h) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Any[IInjectionHeuristic] (IEnumerable`1 source, System.Func`2 predicate) [0x00000] in <filename unknown>:0
at Ninject.Selection.Selector.<SelectPropertiesForInjection>b__1 (System.Reflection.PropertyInfo p) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateWhereIterator>c__Iterator35`1[System.Reflection.PropertyInfo].MoveNext() [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddEnumerable (IEnumerable`1 enumerable) [0x00000] in <filename unknown>:0
at System.Collections.Generic.List`1[System.Reflection.PropertyInfo].AddRange (IEnumerable`1 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__DisplayClass3.<GetPlan>b__1 (IPlanningStrategy s) [0x00000] in <filename unknown>:0
at Ninject.Infrastructure.Language.ExtensionsForIEnumerableOfT.Map[IPlanningStrategy] (IEnumerable`1 series, System.Action`1 action) [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.<Resolve>b__7 (IContext context) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator27`2[Ninject.Activation.IContext,System.Object].MoveNext() [0x00000] in <filename unknown>:0
at System.Linq.Enumerable+<CreateCastIterator>c__Iterator17`1[NinjectIFPropError.IDummy].MoveNext() [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Single[IDummy] (IEnumerable`1 source, System.Func`2 predicate, Fallback fallback) [0x00000] in <filename unknown>:0
at System.Linq.Enumerable.Single[IDummy] (IEnumerable`1 source) [0x00000] in <filename unknown>:0
at Ninject.ResolutionExtensions.Get[IDummy] (IResolutionRoot root, Ninject.Parameters.IParameter[] parameters) [0x00000] in <filename unknown>:0
at NinjectIFPropError.Program.Main (System.String[] args) [0x00018] in /home/roger/Projects/NinjectIFPropError/Main.cs:38
私は、通常の.NETフレームワークを使用してWin7マシン上であなたのサンプルを修正せずにまっすぐに実行しました。 – Dervall
モノラルビルドを試しましたか? –