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:
Hi, I can reproduce the issue
Server code (dotnet core 3.1):
Client code:
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
So possible fix would be just add a cast to Object: