2

So what I'm doing is collecting some data, opening a pop up window to allow the user some additional selections, then closing the pop up and passing back the selections to the parent window as an array, then sending all this info off to a signalR backend for processing.

The problem is, after passing the array from the popup window back to the parent window and sending it to signalr, the signalr server complains about formatting.

[10:49:02 GMT-0400 (Eastern Daylight Time)]
SignalR: dealshub.SubmitDealsToEngine failed to execute.
Error: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[System.String]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object.
JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path '0', line 1, position 5.

Upon further inspection debugging in visual studio I'm seeing the __proto_ and length fields disappear after being passed to the parent window, the actual information I put into the array is still present however.

Currently I'm working around this by just creating a new array back in the parent window and pushing the objects from the passed array onto it. This shuts up signalr and brings back the proto and lenght fields.

Wanting to know what is changing here and if there's a way to make it pass correctly.

piggy
  • 365
  • 3
  • 19
Hardycore
  • 334
  • 4
  • 17

1 Answers1

0

It looks very much like the problem described here. You can bypass the problem by supplying a JSON serializer to the connection as described here, or by any other method from my answer.

In order to use a custom JSON serializer, include the following code:

$.connection.hub.json = {
    parse: function(text, reviver) {
        console.log("Parsing JSON");
        return window.JSON.parse(text, reviver);
    },
    stringify: function(value, replacer, space) {
        return window.JSON.stringify(value, replacer, space);
    }
};
Community
  • 1
  • 1
Tomer
  • 1,606
  • 12
  • 18