RegistryManager.GetTwinAsync()在.net框架中抛出错误 [英] RegistryManager.GetTwinAsync() throwing error in .net framework

查看:68
本文介绍了RegistryManager.GetTwinAsync()在.net框架中抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是获取Device Twin的以下代码。

This is the Following code to get the Device Twin.

  string ioTHubConnectionString = Settings.IotHub;  

 string ioTHubConnectionString = Settings.IotHub; 

RegistryManager registryManager = RegistryManager.CreateFromConnectionString(ioTHubConnectionString) var devicelist = registryManager.GetDeviceAsync(deviceId).Result;

注意:与UpdateDeviceAsync(deviceId)的问题相同;

Note: same as issue for UpdateDeviceAsync(deviceId);

此抛出异常: 

This Throwing Exception: 

我不想使用DeviceClient对象获取DeviceTwin数据 - 因为我们需要更新所需的属性。

I don't want to Get the DeviceTwin data using DeviceClient object- as we need to update the desired Properties.

请向我提供解决方案

谢谢,

Bhagya

推荐答案

Hello Bhagya,

Hello Bhagya,

我测试了两个版本的Microsoft.Azure.Devices:stable 1.6。 0和1.16.0-在.NET Framework控制台应用程序中使用以下代码进行预览,但无法重现您的问题。

I test two versions of Microsoft.Azure.Devices: stable 1.6.0 and 1.16.0-preview with the following code in a .NET Framework Console App, but can't reproduce your issue.

            RegistryManager registryManager = RegistryManager.CreateFromConnectionString(connectionString);
            Device device = registryManager.GetDeviceAsync(deviceId).Result;
            Twin deviceTwin = await registryManager.GetTwinAsync(deviceId);

            device.Status = DeviceStatus.Enabled;
            device.ETag = deviceTwin.ETag;
            Device result = await registryManager.UpdateDeviceAsync(device, true);

API  registryManager.GetTwinAsync()返回Microsoft.Azure.Devices.Shared.Twin而不是您的异常信息中出现的Microsoft.Azure.Devices.Shared.TwinCollection。因此,如果您可以显示相关的代码行和Microsoft.Azure.Devices
nuget包版本,我们可以进一步调查。

The API registryManager.GetTwinAsync() returns Microsoft.Azure.Devices.Shared.Twin not Microsoft.Azure.Devices.Shared.TwinCollection that occurs in your exception information. So if you can show related code lines and Microsoft.Azure.Devices nuget package version, we can do further investigation.


这篇关于RegistryManager.GetTwinAsync()在.net框架中抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆