Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exception in UWP app on using Microsoft.Azure.Devices.Client

When i try to use code as mentioned in https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-twin-getstarted in a UWP app, await Client.GetTwinAsync(); throws following exception. I have tried on two different machine but same error, even calling OpenAsync results in same exception. I am trying to create UWP app so that I can deploy it on IOT device.

{System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Security, Version=4.0.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Net.Security, Version=4.0.1.2, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.Azure.Devices.Client.DeviceClient.<>c.b__74_2(Task t)
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at AzureIoTSuiteUWPDevice.MainPage.d__34.MoveNext()}
like image 238
Pankaj Garg Avatar asked May 07 '26 10:05

Pankaj Garg


1 Answers

I have downloaded the solution you provided.The issue would be fixed by changing the Min Version of target to 16299 in solution properties. You can refer to here to get how to choose a UWP version.

Minimum Version. This sets the TargetPlatformMinVersion setting in your project file. It also determines the value of the TargetDeviceFamily@MinVersion attribute in your app package manifest. The value you choose specifies the minimum version of the UWP platform that your project can work with.

enter image description here

In addition, you should select Private Networks(Client & Server) in the Capabilities(Package.appxmanifest) to allow your app to access the IoT Hub.

privateNetworkClientServer
On Windows, this provides access to a home or work network – the app can send information to or from your computer and other computers on the same network. On Windows Phone, provides the same access as internetClient or internetClientServer.

like image 184
Michael Xu Avatar answered May 11 '26 17:05

Michael Xu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!