In my project I am using Autofac. Previously it was working fine. Now I have added some new code in Autofac and it's giving me "The creation delegate must not return null " error.
The changes that I have made are as follows
builder.Register<Rep>(c => {
/*Get Session and LoginId*/
return session.CreateQuery(@"from Rep where LoginId='" +
LoginId+ "'").List<Rep>().
FirstOrDefault() ?? new Rep();
});
builder.Register<TestPermissionHelper>();
Now in the Global.asax
, in Applicaiton_PostAuthenticate()
method I am resolving TestPermissionHelper
.
The interesting thing is that, when I am hitting the login page at the time it is giving me error, else it is working fine.
I know it is hard to understand the entire picture from this small code. It will be great if someone can at least tell me, in general what are the possible reason for this type of error.
Thanks
Note: If it can help, I am also giving the Stack Trace of the error
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)