title: Handling negotiation exception in SignalR
body: <p>I have a Silverlight 5 application accessing a server using SignalR. Most of the times this works fines but now and then when running in debug I get an error during negotiation. I'm thinking that this may be because my local ISS installation runs out of connections.</p>
  
  <p>Anyway, when this occurs, the Unhandled Exception handler in my application is called. I want to change this, so that I can handle the exception local to the initialization of SignalR. I don't want the negotiation error to propagate to my central error handler.</p>
  
  <p>I have a piece of code which looks as follows:</p>
  
  <pre><code>     var uri = Application.Current.Host.Source.GetComponents(UriComponents.Scheme | UriComponents.HostAndPort, UriFormat.Unescaped);
  
       _hubConnection = new HubConnection(uri);
       var hub = _hubConnection.CreateProxy("stuffhub");
       hub.On&lt;Stuff&gt;("Stuff", message =&gt; DoStuff());
  
       var transport = new LongPollingTransport();
       _hubConnection.Start(transport);
  </code></pre>
  
  <p>This code executes fine most of the time, but some times the following exception is handed to my central unhandled excpetion handler a few seconds after the code above has executed.</p>
  
  <pre><code>Message: Exception(s) occurred : .
  [ Exception(s) occurred : .
  [ Exception(s) occurred : .
  [ Exception(s) occurred : .
  [ System.InvalidOperationException: Server negotiation failed.
     vid SignalR.Client.Transports.HttpBasedTransport.&lt;GetNegotiationResponse&gt;b__0(IResponse     response)
     vid SignalR.TaskAsyncHelper.FromMethod[T1,TResult](Func`2 func, T1 arg) ]
   ]
   ]
  </code></pre>
  
  <p>]</p>
  
  <p>The StackTrace of the ApplicationUnhandledExceptionEventArgs is:</p>
  
  <pre><code> at System.Threading.Tasks.Task.Finalize()
  </code></pre>