title: Why does my ServiceStack service throw an exception?
body: <p>I have constructed a simple Rest service using <a href="http://www.servicestack.net" rel="nofollow">ServiceStack</a> (which is brilliant), that returns a list of key value pairs.</p>
  
  <p>My service looks like this:</p>
  
  <pre><code> public class ServiceListAll : RestServiceBase&lt;ListAllResponse&gt;
  {
      public override object OnGet(ListAllResponse request)
      {          
          APIClient c = VenueServiceHelper.CheckAndGetClient(request.APIKey, VenueServiceHelper.Methods.ListDestinations);
  
          if (c == null)
          {
              return null;
          }
          else
          {
              if ((RequestContext.AbsoluteUri.Contains("counties")))
              {
                  return General.GetListOfCounties();
              }
  
              else if ((RequestContext.AbsoluteUri.Contains("destinations")))
              {
                  return General.GetListOfDestinations();
              }
  
              else
              {
                  return null;
              }
          }
      }
  }
  </code></pre>
  
  <p>my response looks like this:</p>
  
  <pre><code>    public class ListAllResponse
  {
      public string County { get; set; }
      public string Destination { get; set; }
      public string APIKey { get; set; }     
  }
  </code></pre>
  
  <p>and I have mapped the rest URL as follows:</p>
  
  <pre><code>.Add&lt;ListAllResponse&gt;("/destinations")
  .Add&lt;ListAllResponse&gt;("/counties")
  </code></pre>
  
  <p>when calling the service </p>
  
  <blockquote>
    <p><a href="http://localhost:5000/counties/?apikey=xxx&amp;format=xml" rel="nofollow">http://localhost:5000/counties/?apikey=xxx&amp;format=xml</a></p>
  </blockquote>
  
  <p>I receive this exception (a breakpoint in the first line of the service is not hit):</p>
  
  <blockquote>
    <p>
    
    NullReferenceException
    
    Object reference not set to an instance of an object.
    
    
    at ServiceStack.Text.XmlSerializer.SerializeToStream(Object obj, Stream stream) at ServiceStack.Common.Web.HttpResponseFilter.&lt;GetStreamSerializer&gt;b_<em>3(IRequestContext r, Object o, Stream s) at ServiceStack.Common.Web.HttpResponseFilter.&lt;&gt;c</em>_DisplayClass1.&lt;GetResponseSerializer&gt;b__0(IRequestContext httpReq, Object dto, IHttpResponse httpRes) at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)
    
    
    </p>
  </blockquote>
  
  <p>The exception is thrown regardless of whether I include any parameters in call or not. I have also created a number of other services along the same lines in the same project which work fine. Can anyone point me in the right direction as to what this means?</p>