SignalR: Unable to convert from System.String to System.Collections.Generic.IEnumerable

Below is the code for my client, which I use on two different pages:

<script src='<%= Page.ResolveUrl("~/resources/js/jquery-1.6.4.min.js") %>' type="text/javascript"></script>re
    <script type="text/javascript">
        jQuery.noConflict();
    </script>
    <script src='<%= Page.ResolveUrl("~/resources/js/jquery.signalR-1.2.0.min.js") %>' type="text/javascript"></script>
    <script src='<%= Page.ResolveUrl("~/signalr/hubs") %>' type="text/javascript"></script>
    <script type="text/javascript">
        jQuery(function () {
            // Declare a proxy to reference the hub. 
            var usr = jQuery.connection.notificationHub;
            jQuery.connection.hub.logging = true;

            jQuery.connection.hub.qs = "clientId=arif";// +readCookie("personId");

            jQuery.connection.hub.start().done(function () {

            });
            usr.client.showUsersOnLine = function (data) {
            };

        });

    </script>

On one page it connects and works fine, but on another page it gives me the following error:

[ArgumentException: Could not cast or convert from System.String to System.Collections.Generic.IEnumerable`1[Microsoft.AspNet.SignalR.Hubs.HubDispatcher+ClientHubInfo].]
   Newtonsoft.Json.Utilities.ConvertUtils.EnsureTypeAssignable(Object value, Type initialType, Type targetType) +241
   Newtonsoft.Json.Utilities.ConvertUtils.ConvertOrCast(Object initialValue, CultureInfo culture, Type targetType) +123
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureType(JsonReader reader, Object value, CultureInfo culture, JsonContract contract, Type targetType) +238

[JsonSerializationException: Error converting value "[{"name": "notificationhub"}]" to type 'System.Collections.Generic.IEnumerable`1[Microsoft.AspNet.SignalR.Hubs.HubDispatcher+ClientHubInfo]'. Path '', line 1, position 35.]
   Microsoft.Owin.Host.SystemWeb.Infrastructure.<>c__DisplayClass1.<GetRethrowWithNoStackLossDelegate>b__0(Exception ex) +27
   Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow() +34
   Microsoft.Owin.Host.SystemWeb.CallContextAsyncResult.End(IAsyncResult result) +49
   Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.EndProcessRequest(IAsyncResult result) +7
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9628972
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

The only difference that I see is: When the consul command is called, the 'connectionData' parameter is different: For the page where it works:

connectionData  [{"name":"notificationhub"}]

And for the page where it does not work, it looks like this:

connectionData  "[{\"name\": \"notificationhub\"}]"

Can someone suggest that I am actually absent or that I should check?

+4
source share
1 answer

Ok, that’s why I got this error.

jquery.signalr-2.0.0.js 2578

connection.data = connection.json.stringify(subscribedHubs);

, JSON.stringify . prototype.js, JSON.stringify, .

, F12:

JSON.stringify([{name:"testhub"}]);

if "[{"name":"testhub"}]", ""[{\"name\": \"testhub\"}]"", stringify .

+5

Source: https://habr.com/ru/post/1527248/


All Articles