jamiewest / signalr_core

ASP.NET Core SignalR Dart Client
https://pub.dev/packages/signalr_core
MIT License
90 stars 58 forks source link

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

Open dunghoang046 opened 3 years ago

dunghoang046 commented 3 years ago

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

CarvalhoWesley commented 3 years ago

@dunghoang046, would you have an example code?

a-bullert commented 2 years ago

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

DittoGod commented 1 year ago

Any update on this?