Azure / azure-iot-sdk-csharp

A C# SDK for connecting devices to Microsoft Azure IoT services
Other
463 stars 493 forks source link

[Bug Report] WebSockets not working on Web Assembly #3412

Open imatrisciano opened 8 months ago

imatrisciano commented 8 months ago

Context

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

timtay-microsoft commented 8 months ago

IIRC, we currently don't have any plans to add support for Web assembly, but we are tracking it in the discussion below:

https://github.com/Azure/azure-iot-sdk-csharp/discussions/2104