Возможно, пытается сделать слишком много вещей одновременно.
Удалить StartIfNeededAsync
из конструктора
public HubUtil(string baseUrl) {
connection = new HubConnectionBuilder()
.AddJsonProtocol()
.WithUrl(baseUrl) // baseUrl is "https://hostname/hubname"
.Build();
connection.Closed += Connection_Closed;
}
private Task Connection_Closed(Exception arg) {
return StartIfNeededAsync();
}
public async Task StartIfNeededAsync() {
if (_connectionState == ConnectionState.Connected) {
return;
}
try {
await connection.StartAsync();
_connectionState = ConnectionState.Connected;
} catch (Exception ex) {
_connectionState = ConnectionState.Faulted;
throw;
}
}
//...
и сделать его явным вызовом, также принимая во внимание SSL.
//Handle TLS protocols
System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Tls
| System.Net.SecurityProtocolType.Tls11
| System.Net.SecurityProtocolType.Tls12;
var hub = new HubUtil("https://host/hubname");
await hub.StartIfNeededAsync();
hub.Invoke("checkin", "id", "");