Azure / azure-iot-sdk-csharp

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

Exception when running with SDK with Xamarin on iOS #972

Closed markrad closed 5 years ago

markrad commented 5 years ago

Description of the issue:

IoT C# client running on iOS (both the simulator and a real device) throws an exception that suggests it is not identifying the host OS correctly

Code sample exhibiting the issue:

https://github.com/tele-bird/iothub-connect

Exception Information:

{System.TypeInitializationException: The type initializer for 'Microsoft.Win32.Registry' threw an exception. ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
  at Microsoft.Win32.RegistryKey..ctor (Microsoft.Win32.RegistryHive hiveId) [0x00006] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/mcs/class/corlib/Microsoft.Win32/RegistryKey.cs:51 
  at Microsoft.Win32.Registry..cctor () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/mcs/class/corlib/Microsoft.Win32/Registry.cs:40 
   --- End of inner exception stack trace ---
  at Microsoft.Azure.Devices.Client.ProductInfo+<>c.<.ctor>b__9_1 () [0x00000] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at System.Lazy`1[T].ViaFactory (System.Threading.LazyThreadSafetyMode mode) [0x0001c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:327 
--- End of stack trace from previous location where exception was thrown ---

  at System.LazyHelper.ThrowException () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:97 
  at System.Lazy`1[T].CreateValue () [0x0007e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:435 
  at System.Lazy`1[T].get_Value () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/12.10.0.153/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Lazy.cs:509 
  at Microsoft.Azure.Devices.Client.ProductInfo.ToString (System.String format) [0x0007f] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.ProductInfo.ToString (Microsoft.Azure.Devices.Client.UserAgentFormats format) [0x00010] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.ProductInfo.ToString () [0x00000] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttIotHubAdapter.Connect (DotNetty.Transport.Channels.IChannelHandlerContext context) [0x00105] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler.OpenAsyncInternal (System.Threading.CancellationToken cancellationToken) [0x001cc] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.Mqtt.MqttTransportHandler.OpenAsync (System.Threading.CancellationToken cancellationToken) [0x000a2] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.ProtocolRoutingDelegatingHandler.OpenAsync (System.Threading.CancellationToken cancellationToken) [0x001b9] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler+<>c__DisplayClass22_0.<ExecuteWithErrorHandlingAsync>b__0 () [0x00071] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.ErrorDelegatingHandler.ExecuteWithErrorHandlingAsync[T] (System.Func`1[TResult] asyncOperation) [0x0014c] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler+<>c__DisplayClass32_0.<OpenAsyncInternal>b__0 () [0x0009e] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.Transport.RetryDelegatingHandler.EnsureOpenedAsync (System.Threading.CancellationToken cancellationToken) [0x00117] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at Microsoft.Azure.Devices.Client.InternalClient.OpenAsync () [0x0008c] in <fa3e1c20e1654ad5b3c332ecd0fc038a>:0 
  at IotPoc.Device.Iot.IotDevice.Start () [0x00049] in C:\Users\markrad\S\iothub-connect\IotPoc\IotPoc.Device.Iot\IotDevice.cs:62 }
CIPop commented 5 years ago

Likely caused by https://github.com/Azure/azure-iot-sdk-csharp/pull/760/files

@prmathur-microsoft @jadeiceman PTAL

az-iot-builder-01 commented 5 years ago

@CIPop, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey