title: ServiceStack: Null Exception when using HttpResponse
body: <p>I have been loving the clean conventions in ServiceStack however I recently ran into a vexing problem. The user loads a "create" page to create an "ad", then posts the form data. The server in term should process the posted data and redirect the user upon success.</p>
  
  <p>I run this with the debugger. The POST method completes without error, but the server always returns the error after the service is finished:</p>
  
  <pre><code>Object reference not set to an instance of an object. AT 
  </code></pre>
  
  <p><code>CompiledRazorTemplates.Dynamic.dfdcdedabeabca.Execute() at ServiceStack.Razor.Templating.TemplateService.ExecuteTemplate[T](T model, String name, String defaultTemplatePath, IHttpRequest httpReq, IHttpResponse httpRes) at ServiceStack.Razor.RazorFormat.ProcessRazorPage(IHttpRequest httpReq, ViewPageRef razorPage, Object dto, IHttpResponse httpRes) at ServiceStack.Razor.RazorFormat.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, Object dto) at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.&amp;lt;&amp;gt;c__DisplayClass1.&amp;lt;SerializeToStream&amp;gt;b__0(IViewEngine x) at System.Linq.Enumerable.Any[TSource](IEnumerable</code>1 source, Func<code>2 predicate) at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object response, IHttpResponse httpRes) at ServiceStack.Common.Web.HttpResponseFilter.SerializeToStream(IRequestContext requestContext, Object response, Stream responseStream) at ServiceStack.Common.Web.HttpResult.WriteTo(Stream responseStream) at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToOutputStream(IHttpResponse response, Object result, Byte[] bodyPrefix, Byte[] bodySuffix) at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)</code></p>
  
  <p>Ive boiled the code down to this to isolate the issue:</p>
  
  <pre><code>    [Route("/ad/create", Verbs = "GET")]
  public class AdCreateViewModelCriteria
  {
  }
  
  [Route("/ad/create", Verbs = "POST")]
  public class AdCreate
  {
      //some things
  }
  
  public class AdCreateService:Service
  {
  //the error occurs AFTER this method is complete
      public object Post(AdCreate ac)
      {
          try
          {
              //do some stuff
              return new HttpResult()
                         {
                             StatusCode = HttpStatusCode.Redirect,
                             Headers ={{HttpHeaders.Location, "/home"}}
                         };
          }
          catch (Exception e)
          {
              return new HttpResult(e)
                         {
                             StatusCode = HttpStatusCode.InternalServerError
                         };
          }
      }
  
  
      [DefaultView("adcreate")]
      public object Get(AdCreateViewModelCriteria criteria)
      {
          return AdCreateViewModel.Load(criteria,Db);
      }
  }
  </code></pre>