From 8d287333093341c13ef26564725d49ca61a6f3c3 Mon Sep 17 00:00:00 2001 From: barelyprofessional <150058423+barelyprofessional@users.noreply.github.com> Date: Mon, 17 Jun 2024 19:22:04 +0800 Subject: [PATCH] Corrected NullReferenceException due to WsReconnection event being called before the reference to the instance was created --- KfChatDotNetWsClient/ChatClient.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KfChatDotNetWsClient/ChatClient.cs b/KfChatDotNetWsClient/ChatClient.cs index 69d8d33..c7fce27 100644 --- a/KfChatDotNetWsClient/ChatClient.cs +++ b/KfChatDotNetWsClient/ChatClient.cs @@ -43,7 +43,7 @@ public class ChatClient public async Task StartWsClient() { - _wsClient = await CreateWsClient(); + await CreateWsClient(); } public void Disconnect() @@ -51,7 +51,7 @@ public class ChatClient _wsClient.Stop(WebSocketCloseStatus.NormalClosure, "Closing websocket").Wait(); } - private async Task CreateWsClient() + private async Task CreateWsClient() { var factory = new Func(() => { @@ -77,6 +77,7 @@ public class ChatClient { ReconnectTimeout = TimeSpan.FromSeconds(_config.ReconnectTimeout) }; + _wsClient = client; client.ReconnectionHappened.Subscribe(WsReconnection); client.MessageReceived.Subscribe(WsMessageReceived); @@ -85,7 +86,6 @@ public class ChatClient _logger.Debug("Websocket client has been built, about to start"); await client.Start(); _logger.Debug("Websocket client started!"); - return client; } public bool IsConnected()