title: Error: The creation delegate must not return null in Autofac?
body: <p>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 "<strong>The creation delegate must not return null</strong> " error.</p>
  
  <p>The changes that I have made are as follows</p>
  
  <pre><code> builder.Register&lt;Rep&gt;(c =&gt; {
                                        /*Get Session and LoginId*/
  
                                 return session.CreateQuery(@"from Rep where LoginId='" +
                                                     LoginId+ "'").List&lt;Rep&gt;().
                                                     FirstOrDefault() ?? new Rep();
                              });
   builder.Register&lt;TestPermissionHelper&gt;();
  </code></pre>
  
  <p>Now in the <code>Global.asax</code>, in <code>Applicaiton_PostAuthenticate()</code> method I am resolving <code>TestPermissionHelper</code>. </p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>Thanks</p>
  
  <p>Note: If it can help, I am also giving the Stack Trace of the error</p>
  
  <pre><code>    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&amp; newInstance)
     at Autofac.Context.TryResolve(Service service, Object&amp; 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.&lt;&gt;c__DisplayClass2.&lt;CanSupplyValue&gt;b__0()
     at Autofac.Component.Activation.DirectConstructorInvoker.&lt;InvokeConstructor&gt;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&amp; newInstance)
     at Autofac.Context.TryResolve(Service service, Object&amp; 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)
  </code></pre>