0
    
    
        
                    surajlokhandemmew created
                    
                    
                    
                
                ABP Framework version: v8.0.0
UI Type: MVC + Flutter
Database System: MongoDB
Tiered (for MVC) or Auth Server Separated (for Angular): no
Exception message and full stack trace: below is the error and hub code with flutter controller code
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Error parsing handshake response: 'type 'Null' is not a subtype of type 'String' in type cast'
public class ChatMaiHub : AbpHub
{
    private readonly IIdentityUserRepository _identityUserRepository;
    private readonly ILookupNormalizer _lookupNormalizer;
    public ChatMaiHub(IIdentityUserRepository identityUserRepository, ILookupNormalizer lookupNormalizer)
    {
        _identityUserRepository = identityUserRepository;
        _lookupNormalizer = lookupNormalizer;
    }
    public async Task SendMessage(string targetUserName, string message)
    {
        var targetUser = await _identityUserRepository.FindByNormalizedUserNameAsync(_lookupNormalizer.NormalizeName(targetUserName));
        message = $"{CurrentUser.UserName}: {message}";
        await Clients
            .User(targetUser.Id.ToString())
            .SendAsync("ReceiveMessage", message);
    }
}
below is flutter controller
import 'package:mailaundry/presentation/models/authview_model.dart';
import 'package:logging/logging.dart';
import 'package:signalr_netcore/signalr_client.dart';
import '../../mylaundryhub/mylaundryhub_gloabelclass/mylaundryhub_prefsname.dart';
class ChatController {
  late HubConnection _hubConnection;
  final Function(String message) onMessageReceived;
  AuthViewModel authViewModel = AuthViewModel();
  final transportProtLogger = Logger("SignalR - transport");
  final hubProtLogger = Logger("SignalR - hub");
  Future<String> getValidAccessToken() async {
    // Ensure this method handles the potential null case appropriately.
    return await authViewModel.getValidAccessToken() ?? '';
  }
  ChatController({required this.onMessageReceived}) {
    var httpOptions = HttpConnectionOptions(
        logger: transportProtLogger,
        transport: HttpTransportType.ServerSentEvents,
        accessTokenFactory: () async => await getValidAccessToken());
    _hubConnection = HubConnectionBuilder()
        .withUrl("$api/signalr-hubs/chat-mai", options: httpOptions)
        .configureLogging(hubProtLogger)
        .build();
    _hubConnection.on('ReceiveMessage', (arguments) {
      if (arguments != null && arguments.isNotEmpty) {
        onMessageReceived(arguments[0] as String);
      }
    });
    _hubConnection.start();
    //.catchError((error) {
    //print('Connection Failed. Error: $error');
    //});
  }
  Future<void> sendMessage(String targetUserName, String message) async {
    if (_hubConnection.state == HubConnectionState.Connected) {
      await _hubConnection
          .invoke('SendMessage', args: [targetUserName, message]);
    } else {
      print('Connection is not established. Message not sent.');
      // Optionally, implement a retry mechanism or inform the user.
    }
  }
}
                        3 Answer(s)
- 
    0
hi
We aren't familiar with Flutter. Do you get any errors on the backend app?
 - 
    0
no i resolved the error basically had to turn on websocket in IIS, but as this question is already raised i am having another issue , can i ask here or should i raise another question??
 - 
    0
Sure