当我尝试在UWP应用程序中使用https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-csharp-csharp-twin-getstarted中提到的代码时,等待Client.GetTwinAsync();抛出异常。 我尝试过两台不同的机器,但是同样的错误,甚至调用OpenAsync导致同样的异常。我正在尝试创建UWP应用程序,以便我可以在IOT设备上部署它。
{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()}
答案 0 :(得分:2)
就我而言,我不得不将NuGet包Microsoft.Azure.Devices.Client降级到1.6.0版,一切正常。
答案 1 :(得分:1)
我已经下载了您提供的解决方案。通过在解决方案属性中将目标的最小版本更改为16299,可以解决该问题。您可以参考here了解如何选择UWP版本。
最低版本。这将在项目文件中设置TargetPlatformMinVersion设置。它还确定应用包清单中TargetDeviceFamily @ MinVersion属性的值。您选择的值指定项目可以使用的UWP平台的最低版本。
此外,您应在Capabilities(Package.appxmanifest)中选择专用网络(客户端和服务器),以允许您的应用访问IoT中心。
<强> privateNetworkClientServer 强>
在Windows上,这提供了对家庭或工作网络的访问 - 应用程序可以向您的计算机和同一网络上的其他计算机发送信息。在Windows Phone上,提供与internetClient或internetClientServer相同的访问权限。