Colin Desmond
Colin Desmond

Reputation: 4854

Module twin coming back empty

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

debugger showing all properties as null

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

Answers (1)

Rita Han
Rita Han

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:

enter image description here

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);

enter image description here

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

Related Questions