Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebSockets transport: error calling onReceive, error: type 'List<dynamic>' is not a subtype of type 'List<Object>?' #13

Closed
golovin-igor opened this issue Oct 9, 2021 · 1 comment

Comments

@golovin-igor
Copy link

Hi, I can reproduce the issue

Server code (dotnet core 3.1):

 await Clients.Caller.SendAsync("someMessage", JsonConvert.SerializeObject(new
          {
                some_data= id.ToString(),
                some_other_data = somethingElse.ToString()
          }));

Client code:

import 'package:signalr_netcore/signalr_client.dart';

//all logs are enabled
Logger.root.level = Level.ALL;

Logger.root.onRecord.listen((record) {
      print('${record.level.name}: ${record.time}: ${record.message}');
    });

//specify hub connection options
final httpConnectionOptions = new HttpConnectionOptions(
          accessTokenFactory: () async => await getUserToken(),
          logger: transportProtLogger,
          httpClient: WebSupportingHttpClient(null,
              httpClientCreateCallback: _httpClientCreateCallback),
          logMessageContent: true);


//build the hub connection
final hubConnection = HubConnectionBuilder()
               .withUrl(mainServer + '/myHub', options: httpConnectionOptions)
               .configureLogging(hubProtLogger)
               .withAutomaticReconnect(
                    retryDelays: [2000, 5000, 10000, 20000, 50000]).build();

//...

 _hubConnection.on('someMessage', _handleSomeMessage);

//...


 void _handleSomeMessage(List<Object>? args) {
//This would never call, due to the following error in the logs:
2I/flutter (11935): SEVERE: 2021-10-09 00:33:20.786183: (WebSockets transport) error calling onReceive, error: type 'List<dynamic>' is not a subtype of type 'List<Object>?'

}

After some digging I figured out that error goes from JsonHubProtocol class where invocation message got parsed, e.g. :
signalr_core\json_hub_protocol.dart

class JsonHubProtocol implements IHubProtocol {

//....

static InvocationMessage _getInvocationMessageFromJson(
      Map<String, dynamic> jsonData) {
    final MessageHeaders? headers =
        createMessageHeadersFromJson(jsonData["headers"]);
    final message = InvocationMessage(
        jsonData["target"],

//Here jsonData produces List<dynamic> instead of List<Object>
        jsonData["arguments"],

        jsonData["streamIds"],
        headers,
        jsonData["invocationId"]);

    _assertNotEmptyString(
        message.target, "Invalid payload for Invocation message.");
    if (message.invocationId != null) {
      _assertNotEmptyString(
          message.invocationId, "Invalid payload for Invocation message.");
    }

    return message;
  }

So possible fix would be just add a cast to Object:

        jsonData["arguments"]?.cast<Object>().toList(),
golovin-igor added a commit to golovin-igor/signalr_client that referenced this issue Oct 9, 2021
Fix on error calling onReceive, error: type 'List<dynamic>' is not a subtype of type 'List<Object>?'

sefidgaran#13
sefidgaran added a commit that referenced this issue Nov 1, 2021
@sefidgaran
Copy link
Owner

Hi @golovin-igor
Thanks for your Pull Request.
It is already approved and published.
I am going to close this issue.

Regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants