Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetTwinAsync returns a device with null properties

I'm trying to read the twin of my device from the registry manager. This is my code:

DeviceClient client = 
DeviceClient.CreateFromConnectionString(DeviceConnectionString, 
TransportType.Mqtt);

Twin deviceTwin = await deviceClient.GetTwinAsync();
Console.WriteLine(deviceTwin.ToJson());

However, the Json I'm getting is the following.

{"deviceId":null,"etag":null,"version":null,"properties":{"desired":{"$version":1},"reported":{"$version":1}}}
like image 802
ChuckMorris42 Avatar asked Apr 23 '26 17:04

ChuckMorris42


2 Answers

I reproduced your issue.

For this problem, you can open an issue on azure-iot-sdk-csharp repository.

For workarounds, you can either use REST API like this:

enter image description here

Or use Azure IoT Service SDK like this:

using Microsoft.Azure.Devices;

...

 var client = RegistryManager.CreateFromConnectionString(IoTHubConnectionString);
 var twinData = await client.GetTwinAsync(deviceId);
 Console.WriteLine(twinData.ToJson());
like image 188
Rita Han Avatar answered Apr 25 '26 08:04

Rita Han


This is not an issue and/or workaround. Documentation states:

Retrieve the device twin properties for the current device. For the complete device twin object, use Microsoft.Azure.Devices.RegistryManager.GetTwinAsync(string deviceId).

like image 24
Dick van Straaten Avatar answered Apr 25 '26 09:04

Dick van Straaten