jamiewest/signalr_core

_CastError (type '_CastError' is not a subtype of type 'Exception' in type cast)

dunghoang046 opened this issue · 3 comments

why using await connection.start() _CastError (type '_CastError' is not a subtype of type 'Exception' in type cast)
not connect start. I using signalr_core 1.1.1 and dotnet core 2.1

I/flutter (14152): The HttpConnection connected successfully.
I/flutter (14152): Sending handshake request.
I/flutter (14152): Hub handshake failed with error 'Null check operator used on a null value' during start(). Stopping HubConnection.
I/flutter (14152): HubConnection failed to start successfully because of error '{type '_CastError' is not a subtype of type 'Exception' in type cast.toString()}'.
E/flutter (14152): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type '_CastError' is not a subtype of type 'Exception' in type cast

@dunghoang046, would you have an example code?

We're seeing the same issue reported via Sentry.
This is our code sample (with some irrelevant details removed):

class ACSignalRService {

static final String _signalRRoute = 'XXXXXXXXXX';

HubConnection _connection;

ACSignalRService() {
_connection = HubConnectionBuilder()
.withUrl(
_signalRRoute,
HttpConnectionOptions( ))
.build();
}

void stopConnection() {
_connection.stop();
}

Future startConnection(StreamController streamController) async {
if (_connection.state == HubConnectionState.disconnected) {
await _connection.start();
_connection.on('XXXXXX', (message) {
// doing something here
});
}
}

startConnection is called from somewhere else in our code. If we have an error on our side, it could be called multiple times.
But still, the error reported here, is a cast exception in the libraries code. This is the stack trace:

_CastError: type '_CastError' is not a subtype of type 'Exception' in type cast
File "hub_connection.dart", line 221, in HubConnection._startInternal
File "hub_connection.dart", line 154, in HubConnection._startWithStateTransitions

Any update on this?