title: Self Hosting WebApi C# with WindowsForms error
body: <p>I took a sample project webapi Self Hosting, the Microsoft page. The webapi starts correctly, but when accessing the address, it gives the error below. I'm using VS2010 and Windows Forms. With Console Applicattion its working, and Windows Forms not working.</p>
  
  <p>Program code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.Web.Http.SelfHost;
  using System.Web.Http;
  using System.Net.Http;
  
  namespace WindowsFormsApplication1
  {
      public partial class Form1 : Form
      {
  
          HttpSelfHostServer server;
          HttpSelfHostConfiguration config;
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
  
              var config = new HttpSelfHostConfiguration("http://localhost:9090");
  
              config.Routes.MapHttpRoute(
                  "API Default", "api/{controller}/{id}",
                  new { id = RouteParameter.Optional });
  
              using (HttpSelfHostServer server = new HttpSelfHostServer(config))
              {
                  server.OpenAsync().Wait();
              }
          }
  
          private void button2_Click(object sender, EventArgs e)
          {
              HttpClient client = new HttpClient();
              client.BaseAddress = new Uri("http://localhost:9090");
  
              //Console.WriteLine("Products in '{0}':", category);
  
              string query = string.Format("api/products?category={0}", "testes");
  
              var resp = client.GetAsync(query).Result;
              //resp.EnsureSuccessStatusCode();
  
              var products = resp.Content.ReadAsAsync&lt;string&gt;().Result;
              MessageBox.Show(products);
          }
      }
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>namespace SelfHost
  {
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Net;
      using System.Web.Http;
  
  
      public class ProductsController : ApiController
      {
  
          public string GetProductsByCategory(string category)
          {
              return (category ?? "Vazio");
          }
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>This XML file does not appear to have any style information associated with it. The document tree is shown below.
  &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.SelfHost.HttpSelfHostServer.ProcessRequestContext(ChannelContext channelContext, RequestContext requestContext)
  &lt;/StackTrace&gt;
  &lt;/Error&gt;
  </code></pre>