私のプロジェクトでは Autofac を使用しています。以前は正常に動作していました。Autofac に新しいコードを追加したところ、「The creation delegate must not return null」というエラーが表示されました。
私が行った変更は次のとおりです
builder.Register<Rep>(c => {
/*Get Session and LoginId*/
return session.CreateQuery(@"from Rep where LoginId='" +
LoginId+ "'").List<Rep>().
FirstOrDefault() ?? new Rep();
});
builder.Register<TestPermissionHelper>();
今、Global.asax
メソッドApplicaiton_PostAuthenticate()
で私は解決してTestPermissionHelper
います。
興味深いことに、ログインページにアクセスするとエラーが発生しますが、それ以外は正常に機能しています。
この小さなコードから全体像を理解するのは難しいことはわかっています。一般的に、このタイプのエラーの考えられる理由は何か、誰かが少なくとも私に教えてくれれば素晴らしいことです。
ありがとう
注:それが役立つ場合は、エラーのスタックトレースも提供しています
Stack trace: at Autofac.Component.Activation.DelegateActivator.ActivateInstance(IContext context, IEnumerable`1 parameters)
at Autofac.Component.Registration.ResolveInstance(IContext context, IEnumerable`1 parameters, IDisposer disposer, Boolean& newInstance)
at Autofac.Context.TryResolve(Service service, Object& instance, IEnumerable`1 parameters)
at Autofac.Context.Resolve(Service service, IEnumerable`1 parameters)
at Autofac.Context.Resolve(Type serviceType, IEnumerable`1 parameters)
at Autofac.Component.Activation.AutowiringParameter.<>c__DisplayClass2.<CanSupplyValue>b__0()
at Autofac.Component.Activation.DirectConstructorInvoker.<InvokeConstructor>b__0(Func`1 pa)
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Autofac.Component.Activation.DirectConstructorInvoker.InvokeConstructor(IContext context, IEnumerable`1 parameters, ConstructorInfo ci, Func`1[] args)
at Autofac.Component.Activation.ReflectionActivator.ConstructInstance(ConstructorInfo ci, IContext context, IEnumerable`1 parameters, Func`1[] parameterAccessors)
at Autofac.Component.Activation.ReflectionActivator.ActivateInstance(IContext context, IEnumerable`1 parameters)
at Autofac.Component.Registration.ResolveInstance(IContext context, IEnumerable`1 parameters, IDisposer disposer, Boolean& newInstance)
at Autofac.Context.TryResolve(Service service, Object& instance, IEnumerable`1 parameters)
at Autofac.Context.Resolve(Service service, IEnumerable`1 parameters)
at Autofac.Context.Resolve(Type serviceType, IEnumerable`1 parameters)
at Autofac.Context.Resolve[TService](IEnumerable`1 parameters)
at Autofac.Context.Resolve[TService](Parameter[] parameters)
at Autofac.Container.Resolve[TService](Parameter[] parameters)