Hello,
I'm trying to partially update desired properties in Module Twin. I'm using RegistryManager.UpdateTwinAsync with string overload. I'm using Microsoft.Azure.Devices version 1.41.0 and Microsoft.Azure.Devices.Client 1.42.3
private async Task UpdateAsync(string deviceId, string moduleId, string patch)
{
var manager = GetManager();
var twin = await manager.GetTwinAsync(deviceId, moduleId) ??
throw new ModuleTwinNotFoundException($"Twin doesn't exist for the deviceId: {deviceId}.");
await manager.UpdateTwinAsync(twin.DeviceId, moduleId, patch, twin.ETag);
}
Given the desired state before update:
"desired": {
"$metadata": {
...
},
"$version": 7387,
"current": {
"Available": [
"a"
],
"Name": "name"
},
"installed": {
"name": "name2",
"version": "1.5.1"
}
},
...
I'm invoking UpdateTwinAsync(twin.DeviceId, moduleId, patch, twin.ETag); with patch:
{properties:{desired:{installed:{"name":"name3","version":"2.3.4"}}}}
or with
{"properties":{"desired":{"installed":{"name":"name3","version":"2.3.4"}}}}
End result in Module Twin:
"desired": {
"$metadata": {
...
},
"$version": 7389,
"installed": {
"name": "name3",
"version": "2.3.4"
}
},
After the UpdateTwinAsync is invoke "current" node, which is not in the patch request, is removed:
"current": {
"Available": [
"a"
],
"Name": "name"
}
I also tried to used Twin overload pseudo code below, but the end result was the same.
var twin = new Twin(deviceId)
{
ModuleId = moduleId
};
twin.Properties.Desired[name] = desired;
Am I doing something wrong? Or should I use different approach.
Hello,
I'm trying to partially update desired properties in Module Twin. I'm using RegistryManager.UpdateTwinAsync with string overload. I'm using Microsoft.Azure.Devices version 1.41.0 and Microsoft.Azure.Devices.Client 1.42.3
Given the desired state before update:
I'm invoking UpdateTwinAsync(twin.DeviceId, moduleId, patch, twin.ETag); with patch:
or with
End result in Module Twin:
After the UpdateTwinAsync is invoke "current" node, which is not in the patch request, is removed:
I also tried to used Twin overload pseudo code below, but the end result was the same.
Am I doing something wrong? Or should I use different approach.