连接Azure IoT Hub时,PlatformNotsNotsupportedException在MACOS上扔在MAUI上

发布于 2025-02-02 02:18:22 字数 3321 浏览 4 评论 0原文

我正在MacOS上探索MAUI。我正在移植WPF应用程序来评估功能。该应用程序正在连接到Azure IoT Hub实例。

这是似乎有问题的代码部分:

var iotHubConnectionStringBuilder = IotHubConnectionStringBuilder.Create("HostName=<iotHubConnectionString>");

var registryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionStringBuilder.ToString());

当调用createfromConnectionsTring时,抛出了以下异常:

    Unhandled Exception:
           System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.Http.NSUrlSessionHandler.set_SslProtocols(SslProtocols value)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
at System.Net.Http.HttpClientHandler.InvokeNativeHandlerMethod(String name, Object[] parameters)
at System.Net.Http.HttpClientHandler.SetSslProtocols(SslProtocols value)
at System.Net.Http.HttpClientHandler.set_SslProtocols(SslProtocols value)
at Microsoft.Azure.Devices.Client.Transport.HttpClientHelper..ctor(Uri baseAddress, IAuthorizationProvider authenticationHeaderProvider, IDictionary`2 defaultErrorMapping, TimeSpan timeout, Action`1 preRequestActionForAllRequests, X509Certificate2 clientCert, HttpClientHandler httpClientHandler, ProductInfo productInfo, IWebProxy proxy, Boolean isClientPrimaryTransportHandler)
at Microsoft.Azure.Devices.Client.Transport.HttpTransportHandler..ctor(IPipelineContext context, IotHubConnectionString iotHubConnectionString, Http1TransportSettings transportSettings, HttpClientHandler httpClientHandler, 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.ClientFactory.CreateFromConnectionString(String connectionString, ClientOptions options)
at Microsoft.Azure.Devices.Client.DeviceClient.<>c__DisplayClass8_0.<CreateFromConnectionString>b__0()
at Microsoft.Azure.Devices.Client.DeviceClient.Create(Func`1 internalClientCreator)
at Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(String connectionString, ClientOptions options)
[..]

我播放了不同的httpclient实现,而没有任何积极的结果。而且,令人惊讶的是,它具有相同的呼叫板,并带有nsurlsessionhandler.set_sslprotocols

。 noreferrer”> “

问题

为什么会丢弃此错误?固定?

I am exploring MAUI on macOS. I am porting a WPF application to evaluate the functionalities. The application is connecting to an Azure IoT Hub instance.

Here is the section of code that seems problematic:

var iotHubConnectionStringBuilder = IotHubConnectionStringBuilder.Create("HostName=<iotHubConnectionString>");

var registryManager = RegistryManager.CreateFromConnectionString(iotHubConnectionStringBuilder.ToString());

When calling CreateFromConnectionString, the following exception is thrown:

    Unhandled Exception:
           System.PlatformNotSupportedException: Operation is not supported on this platform.
at System.Net.Http.NSUrlSessionHandler.set_SslProtocols(SslProtocols value)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
--- End of stack trace from previous location ---
at System.Net.Http.HttpClientHandler.InvokeNativeHandlerMethod(String name, Object[] parameters)
at System.Net.Http.HttpClientHandler.SetSslProtocols(SslProtocols value)
at System.Net.Http.HttpClientHandler.set_SslProtocols(SslProtocols value)
at Microsoft.Azure.Devices.Client.Transport.HttpClientHelper..ctor(Uri baseAddress, IAuthorizationProvider authenticationHeaderProvider, IDictionary`2 defaultErrorMapping, TimeSpan timeout, Action`1 preRequestActionForAllRequests, X509Certificate2 clientCert, HttpClientHandler httpClientHandler, ProductInfo productInfo, IWebProxy proxy, Boolean isClientPrimaryTransportHandler)
at Microsoft.Azure.Devices.Client.Transport.HttpTransportHandler..ctor(IPipelineContext context, IotHubConnectionString iotHubConnectionString, Http1TransportSettings transportSettings, HttpClientHandler httpClientHandler, 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.ClientFactory.CreateFromConnectionString(String connectionString, ClientOptions options)
at Microsoft.Azure.Devices.Client.DeviceClient.<>c__DisplayClass8_0.<CreateFromConnectionString>b__0()
at Microsoft.Azure.Devices.Client.DeviceClient.Create(Func`1 internalClientCreator)
at Microsoft.Azure.Devices.Client.DeviceClient.CreateFromConnectionString(String connectionString, ClientOptions options)
[..]

I have played with the different HttpClient implementation without any positive outcome. And, surprinsingly enough, it exhibits the same callstack, with NSUrlSessionHandler.set_SslProtocols on top of it:

HttpClient implementations

Question

Why is this error thrown and how can it be fixed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸 2025-02-09 02:18:22

我正在使用Visual Studio 2022用于Mac版本17.3 Preview 1 。在更新到Visual Studio 2022之后,用于Mac V17.3 Preview 1.1 以及.net Maui Workload,它都可以使用。

我让httpclient实现为nsurlsession

我不确定它的确切原因为什么现在起作用,但是我认为使用预览产品时必定会发生这些问题。

I was using Visual Studio 2022 for Mac version 17.3 Preview 1. After updating to Visual Studio 2022 for Mac v17.3 Preview 1.1 as well as the .net MAUI workload, it worked.

I let the HttpClient implementation to NSUrlSession.

I am not sure the exact reason why it works now but I assume these issues are bound to happen when using preview products.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文