title: 500 error while calling Web API with XML
body: <p>I developed a web api in .net 4.5.  When I test the api call, I am getting a 500 error.  This behavior only happens when I send in XML.  If I use JSON of Form URL encoded string the server handles the request properly.</p>
  
  <p>I added</p>
  
  <pre><code>GlobalConfiguration.Configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
  </code></pre>
  
  <p>to the WebApiConfig.cs and the error returned is:</p>
  
  <pre><code>&lt;Error&gt;&lt;Message&gt;An error has occurred.&lt;/Message&gt;&lt;ExceptionMessage&gt;Object reference not set to an instance of an object.&lt;/ExceptionMessage&gt;&lt;ExceptionType&gt;System.NullReferenceException&lt;/ExceptionType&gt;&lt;StackTrace&gt;   at System.Web.Http.ApiController.&amp;lt;InvokeActionWithExceptionFilters&amp;gt;d__1.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Web.Http.Dispatcher.HttpControllerDispatcher.&amp;lt;SendAsync&amp;gt;d__0.MoveNext()&lt;/StackTrace&gt;&lt;/Error&gt;
  </code></pre>
  
  <p>My header are:</p>
  
  <pre><code>User-Agent: Fiddler
  Content-Type: application/xml; charset=utf-8
  Host: corebeta.pexcard.com
  Content-Length: 119
  </code></pre>
  
  <p>My request is:</p>
  
  <pre><code>&lt;Admin.CardListRequest&gt;
  &lt;username&gt;TestUser&lt;/username&gt;
  &lt;password&gt;GoodPassword&lt;/password&gt;
  &lt;/Admin.CardListRequest&gt;
  </code></pre>
  
  <p>My class looks like this:</p>
  
  <pre><code>public class CardListRequest{
      public string UserName { get; set; }
      public string Password { get; set; }
  }
  </code></pre>
  
  <p>The WebAPI code looks like this(log is using log4net, and nothing is written to that log):</p>
  
  <pre><code>    /// &lt;summary&gt;
      /// Gets the list of open cardholders
      /// &lt;/summary&gt;
      /// &lt;param name="UserName"&gt;The username you use to log on to pexcardadmin.com&lt;/param&gt;
      /// &lt;param name="Password"&gt;The password you use to log on to pexcardadmin.com&lt;/param&gt;
      /// &lt;returns&gt;A list of cardholders with balances&lt;/returns&gt;
      [HttpGet]
      public List&lt;Admin.Account&gt; CardList(string UserName, string Password)
      {
          try
          {
  
              log.Info(String.Format("Admin Parameters: &lt;UserName={0}&gt;", UserName));
              AuthenticateApi(UserName, Password, "cardList");
              var Ret = GetCoreCardCardList(UserName, Password);
              APIData.Response = "Success";
  
  
              return Ret;
          }
          catch (Exception e)
          {
              log.Error(e);
              APIData.Response = e.Message;
              throw e;
          }
          finally
          {
              APIData.ResponseTime = DateTime.Now;
              APILog.LogAPI(APIData);
          }
  
      }
      /// &lt;summary&gt;
      /// Gets the list of open cardholders
      /// &lt;/summary&gt;
      /// &lt;param name="Req"&gt; The Request Parameter&lt;/param&gt;
      /// &lt;returns&gt;A list of cardholders with balances&lt;/returns&gt;
      [HttpPost]
      public List&lt;Admin.Account&gt; CardList(Admin.CardListRequest Req)
      {
          APIData.ParamBlob = JsonConvert.SerializeObject(Req);
          return CardList(Req.UserName, Req.Password);
  
      }
  </code></pre>
  
  <p>Does anyone have any ideas on why this error is being thrown?</p>
  
  <p>Thanks,
  Steven</p>