title: SignalR returns error - Unexpected end when deserializing object
body: <p>I have simple project, where I'm using signalR, When page loads, signalR scripts are loaded succefully, however right after that, call to </p>
  
  <blockquote>
    <p>http://localhost:24634/signalr/signalr/connect?transport=foreverFrame&amp;connectionId=dca2db9c-b16a-4b96-96dc-9a6b187b6d9e&amp;connectionData=[{&quot;name&quot;:&quot;notifier&quot;}]&amp;tid=5&amp;frameId=1</p>
  </blockquote>
  
  <p>returns 500 Internal Server Error, I checked this request in fiddler, error message says</p>
  
  <blockquote>
    <p>Unexpected end when deserializing object.</p>
  </blockquote>
  
  <p>Here's my Hub Definitin</p>
  
  <pre><code>[HubName("notifier")]
      public class PublishingNotifier: Hub
      {   
          [HubMethodName("send")]
          public void SendMessage(string message)
          {
              Clients.getNotification(message);
          }
      }
  </code></pre>
  
  <p>and here's my client code</p>
  
  <pre><code>$(function () {
  
              var publishingNotifier = $.connection.notifier;
  
              publishingNotifier.getNotification = function (message) {
                  // do something
              };
  
              $('input[type=submit][id*=cmsB_ChangeStatusToPublishedTop]').on('click', function (e) {
                  // do something else
              });
  
              $.connection.hub.start();
          });
  </code></pre>
  
  <p>Any ideas what can be cause of this error ?</p>
  
  <p><strong>EDIT</strong>
  Here is Stack Trace information</p>
  
  <blockquote>
    <p>[JsonSerializationException: Unexpected end when deserializing object.
    Line 1, position 2.]<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CheckedRead(JsonReader
    reader) +75<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    Object existingValue) +48<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    Object existingValue) +86<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IWrappedCollection
    wrappedList, JsonReader reader, String reference, JsonArrayContract
    contract) +635<br>
    Newtonsoft.Json.Serialization.&lt;&gt;c_<em>DisplayClass1.&lt;CreateAndPopulateList&gt;b</em>_0(IList
    l, Boolean isTemporaryListReference) +124<br>
    Newtonsoft.Json.Utilities.CollectionUtils.CreateAndPopulateList(Type
    listType, Action<code>2 populateList) +546<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateAndPopulateList(JsonReader
    reader, String reference, JsonArrayContract contract) +101<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    Object existingValue, String reference) +62<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader
    reader, Type objectType, JsonContract contract, JsonProperty member,
    Object existingValue) +113<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueNonProperty(JsonReader
    reader, Type objectType, JsonContract contract, JsonConverter
    converter) +118<br>
    Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader
    reader, Type objectType) +125<br>
    Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader,
    Type objectType) +311<br>
    Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type,
    JsonSerializerSettings settings) +107<br>
    Newtonsoft.Json.JsonConvert.DeserializeObject(String value,
    JsonSerializerSettings settings) +66<br>
    SignalR.JsonNetSerializer.Parse(String json) +57<br>
    SignalR.Hubs.HubDispatcher.CreateConnection(String connectionId,
    IEnumerable</code>1 groups, IRequest request) +140<br>
    SignalR.PersistentConnection.ProcessRequestAsync(HostContext context)
    +227    SignalR.Hubs.HubDispatcher.ProcessRequestAsync(HostContext context) +120<br>
    SignalR.Hosting.AspNet.AspNetHandler.ProcessRequestAsync(HttpContextBase
    context) +463<br>
    SignalR.Hosting.AspNet.HttpTaskAsyncHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext
    context, AsyncCallback cb, Object extraData) +68<br>
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
    +301    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155</p>
  </blockquote>
  
  <p><strong>EDIT2:</strong> </p>
  
  <p>One more note - from the page that runs without any errors, requested url looks like this</p>
  
  <blockquote>
    <p>localhost:24634/signalr/signalr/connect?transport=foreverFrame&amp;connectionId=98e6d5b3-b164-4013-92c2-418aa6254f9e&amp;connectionData=%5B%7B%22name%22%3A%22notifier%22%7D%5D&amp;tid=7&amp;frameId=1</p>
  </blockquote>
  
  <p>and the failing request url looks like this</p>
  
  <blockquote>
    <p>localhost:24634/signalr/signalr/connect?transport=foreverFrame&amp;connectionId=9b398750-99d6-4188-88b5-b41ad9eb82d5&amp;connectionData=[{&quot;name&quot;:&quot;notifier&quot;}]&amp;tid=1&amp;frameId=1</p>
  </blockquote>
  
  <p>As you may notice, the ways connectionData query string parameter is defined in urls are different, in particular, for the first url, connectionData has been url encoded the query string value, and the second query string parameter has been html encoded. I've looked into request headers, failing request Content-Type is text/html, and the second request's Content-Type: application/json.</p>
  
  <p><strong>EDIT 3:</strong></p>
  
  <p>I've found where connectionData get's parsed, in jquery.signalR-0.5.3.js file, here's code that actually encodes connectionData value</p>
  
  <pre><code>if (connection.data) {
    qs += "&amp;connectionData=" + window.escape(connection.data);
  }
  </code></pre>
  
  <p>as you can see, window.escape() is responsible for encoding connectionData, but, if I debug this code, I can see that window.escape(connection.data) indeed html encodes connection.data instead of url encoding. But this is happening only on one page, on anothers, it works as expected.</p>