Azure / Azure/azure-iot-sdk-csharp
[Bug Report] WebSockets not working on Web Assembly
- Dominant language
- C#
- Stars
- 477
- Forks
- 492
- Avg merge
- 9h 55m
- Merged PRs (30d)
- 2
Description
# Context
- **OS, version, SKU and CPU architecture used:** N/A
- **Application's .NET Target Framework :** net8.0
- **Device:** Laptop
- **SDK version used:** 1.42.1
## Description of the issue
Connection to IoT Hub fails when the code is run in Blazor WebAssembly, even if a WebSockets transport is selected.
A `NotSupportedException` is raised with message `Operation is not supported on this platform`
## Code sample exhibiting the issue
`DeviceClient deviceClient = DeviceClient.CreateFromConnectionString(primaryConnectionString, TransportType.Mqtt_WebSocket_Only);`
Here a link to a repository to easily replicate the issue: https://github.com/imatrisciano/azure-device-wasm-client-bug
## Exception stack trace:
> crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
Unhandled exception rendering component: Operation is not supported on this platform.
System.PlatformNotSupportedException: Operation is not supported on this platform.
**at System.Net.Http.SocketsHttpHandler.get_SslOptions()**
at Microsoft.Azure.Devices.Client.Transport.HttpClientHelper..ctor(Uri baseAddress, IAuthorizationProvider authenticationHeaderProvider, IDictionary\`2 defaultErrorMapping, TimeSpan timeout, Http1TransportSettings transportSettings, ProductInfo productInfo, IWebProxy proxy, Boolean isClientPrimaryTransportHandler)
at Microsoft.Azure.Devices.Client.Transport.HttpTransportHandler..ctor(PipelineContext context, IotHubConnectionString iotHubConnectionString, Http1TransportSettings transportSettings, Boolean isClientPrimaryTransportHandler)
at Microsoft.Azure.Devices.Client.InternalClient..ctor(IotHubConnectionString iotHubConnectionString, ITransportSettings[] transportSettings, IDeviceClientPipelineBuilder pipelineBuilder, ClientOptions options)
at Microsoft.Azure.Devices.Client.ClientFactory.CreateFromConnectionString(String connectionString, IAuthenticationMethod authenticationMethod, ITransportSettings[] transportSettings, IDeviceClientPipelineBuilder pipelineBuilder, ClientOptions options)
at Microsoft.Azure.Devices.Client.ClientFactory.CreateFromConnectionString(String connectionString, IAuthenticationMethod authenticationMethod, TransportType transportType, IDeviceClientPipelineBuilder pipelineBuilder, ClientOptions options)
at Microsoft.Azure.Devices.Client.ClientFactory.CreateFromConnectionString(String connectionString, TransportType transportType, ClientOptions options)
at Microsoft.Azure.Devices.Client.DeviceClient.<>c__DisplayClass10_0.b__0()
at Microsoft.Azure.Devices.Client.DeviceClient.Create(Func\`1 internalClientCreator)
at Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(String connectionString, TransportType transportType, ClientOptions options)
at azure_device_client_bug.Pages.Home.ConnectClient()
at azure_device_client_bug.Pages.Home.OnInitializedAsync()
at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync() [blazor.webassembly.js:1:38555](http://localhost:5178/_framework/blazor.webassembly.js)
Contributor guide
Research direction
Reproduce the failure with the linked azure-device-wasm-client-bug sample and the DeviceClient.CreateFromConnectionString call using Mqtt_WebSocket_Only. Start with the stack-trace entry points Microsoft.Azure.Devices.Client.Transport.HttpClientHelper and HttpTransportHandler, then trace client creation through ClientFactory. Done means the sample can connect from Blazor WebAssembly without the platform-not-supported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, wasm
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100