Pankaj Garg
Pankaj Garg

Reputation: 51

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()}

Upvotes: 3

Views: 580

Answers (2)

Alexander Ahrens
Alexander Ahrens

Reputation: 76

In my case I had to downgrade the NuGet package Microsoft.Azure.Devices.Client to Version 1.6.0 and everything worked fine.

Upvotes: 2

Michael Xu
Michael Xu

Reputation: 4432

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.

Upvotes: 2

Related Questions