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.