diff --git a/.github/workflows/ReleaseNotes.md b/.github/workflows/ReleaseNotes.md index e48d96ff..24a926c6 100644 --- a/.github/workflows/ReleaseNotes.md +++ b/.github/workflows/ReleaseNotes.md @@ -1 +1 @@ -* \ No newline at end of file +* [Client] Fixed _PlatformNotSupportedException_ when using Blazor (#1755, thanks to @Nickztar). \ No newline at end of file diff --git a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs index 6ee5b451..e83b6566 100644 --- a/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs +++ b/Source/MQTTnet/Implementations/MqttWebSocketChannel.cs @@ -221,11 +221,22 @@ namespace MQTTnet.Implementations #if !NETSTANDARD1_3 #if !WINDOWS_UWP - clientWebSocket.Options.UseDefaultCredentials = _options.UseDefaultCredentials; + // Only set the value if it is actually true. This property is not supported on all platforms + // and will throw a _PlatformNotSupported_ (i.e. WASM) exception when being used regardless of the actual value. + if (_options.UseDefaultCredentials) + { + clientWebSocket.Options.UseDefaultCredentials = _options.UseDefaultCredentials; + } #endif - clientWebSocket.Options.KeepAliveInterval = _options.KeepAliveInterval; + if (_options.KeepAliveInterval != WebSocket.DefaultKeepAliveInterval) + { + clientWebSocket.Options.KeepAliveInterval = _options.KeepAliveInterval; + } #endif - clientWebSocket.Options.Credentials = _options.Credentials; + if (_options.Credentials != null) + { + clientWebSocket.Options.Credentials = _options.Credentials; + } var certificateValidationHandler = _options.TlsOptions?.CertificateValidationHandler; if (certificateValidationHandler != null)