Reputation: 4854
I am trying to set the desired properties on a Module's device twin, but when I retrieve the twin from the IoT Hub, it comes back full of nulls.
var moduleClient = ModuleClient.CreateFromConnectionString(connectionString);
var moduleTwin = await moduleClient.GetTwinAsync();
When I inspect moduleTwin in the debugger I get
The connection string is the one for the module, copied from the IoT Hub.
Any idea what I am doing wrong?
Upvotes: 2
Views: 522
Reputation: 9700
This is by design. So this issue is expected.
From module app, only has permission to read desired properties and read/write reported properties. See the following:
To access all module twin, you can do it from solution back end and require the ServiceConnect permission. Module twin is newly added. You need Microsoft.Azure.Devices V1.16.0-preview-001 or later. The following is a console app sample.
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(connectionString);
Module module;
var moduleTwin = await registryManager.GetTwinAsync(deviceID, moduleID);
Reference:
understand and use module twins in IoT Hub
"Get started with IoT Hub module identity and module twin using .NET back end and .NET device"
Upvotes: 3