title: SignalR Typenamehandling
body: <p>I am trying to get SignalR to work with custom JsonSerializerSettings for its payload, specifically I'm trying to set <code>TypeNameHandling = TypeNameHandling.Auto</code>.</p>
  
  <p>The problem seems to be, that SignalR uses the settings in <code>hubConnection.JsonSerializer</code> and <code>GlobalHost.DependencyResolver.Resolve&lt;JsonSerializer&gt;()</code> for its internal data structures as well which then causes all kinds of havoc (internal server crashes when I set <code>TypeNameHandling.All</code> as the most crass example, but with <code>TypeNameHandling.Auto</code> I also get problems, particularly when <code>IProgress&lt;&gt;</code> callbacks are involved).</p>
  
  <p>Is there any workaround or am I just doing it wrong?</p>
  
  <p>Sample code to demonstrate:</p>
  
  <p>Server:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          using (WebApp.Start("http://localhost:8080"))
          {
              Console.ReadLine();
          }
      }
  }
  
  public class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          var hubConfig = new HubConfiguration()
          {
              EnableDetailedErrors = true
          };
          GlobalHost.DependencyResolver.Register(typeof(JsonSerializer), ConverterSettings.GetSerializer);
          app.MapSignalR(hubConfig);
      }
  }
  
  public interface IFoo
  {
      string Val { get; set; }
  }
  public class Foo : IFoo
  {
      public string Val { get; set; }
  }
  
  public class MyHub : Hub
  {
      public IFoo Send()
      {
          return new Foo { Val = "Hello World" };
      }
  }
  </code></pre>
  
  <p>Client:</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          Task.Run(async () =&gt; await Start()).Wait();
      }
  
      public static async Task Start()
      {
          var hubConnection = new HubConnection("http://localhost:8080");
          hubConnection.JsonSerializer = ConverterSettings.GetSerializer();
          var proxy = hubConnection.CreateHubProxy("MyHub");
          await hubConnection.Start();
          var result = await proxy.Invoke&lt;IFoo&gt;("Send");
          Console.WriteLine(result.GetType());
      }
  </code></pre>
  
  <p>Shared:</p>
  
  <pre><code>public static class ConverterSettings
  {
      public static JsonSerializer GetSerializer()
      {
          return JsonSerializer.Create(new JsonSerializerSettings()
          {
              TypeNameHandling = TypeNameHandling.All
          });
      }
  }
  </code></pre>