Azure-iot-sdk-csharp: Devices.Client.SetDesiredPropertyUpdateCallbackAsync does not work using c# Device SDK 1.29.0-preview-004

Created on 8 May 2020  ·  10Comments  ·  Source: Azure/azure-iot-sdk-csharp

  • OS, version, SKU and CPU architecture used: Windows 10 Desktop x64
  • Application's .NET Target Framework : netcoreapp3.1
  • Device: Laptop
  • SDK version used: 1.29.0-preview-004

Description of the issue:

When using the latest preview c# device SDK the SetDesiredPropertyUpdateCallbackAsync callback does not fire when changing desired property using Azure IoT Central. When I role back to the latest stable release 1.25.0 the code does work.

Code sample exhibiting the issue:

private const string ModuleConnectionString = "HostName=######.azure-devices.net;DeviceId=########;SharedAccessKey=###########";
private static DeviceClient Client = null;

    static void Main(string[] args)
    {
        Microsoft.Azure.Devices.Client.TransportType transport =
          Microsoft.Azure.Devices.Client.TransportType.Amqp;

        try
        {
            Client = DeviceClient.CreateFromConnectionString(ModuleConnectionString, transport);
            Client.SetConnectionStatusChangesHandler(ConnectionStatusChangeHandler);
            Client.SetDesiredPropertyUpdateCallbackAsync(OnDesiredPropertyChanged, null).GetAwaiter().GetResult();

            Console.WriteLine("Retrieving twin");
            var twinTask = Client.GetTwinAsync();
            twinTask.Wait();
            var twin = twinTask.Result;
            Console.WriteLine(JsonConvert.SerializeObject(twin.Properties));

            Console.WriteLine("Sending app start time as reported property");
            TwinCollection reportedProperties = new TwinCollection();
            reportedProperties["DateTimeLastAppLaunch"] = DateTime.Now;

            Client.UpdateReportedPropertiesAsync(reportedProperties);
        }
        catch (AggregateException ex)
        {
            Console.WriteLine("Error in sample: {0}", ex);
        }

        Console.WriteLine("Waiting for Events.  Press enter to exit...");
        Console.ReadLine();
        Client.CloseAsync().Wait();
    }


    static void ConnectionStatusChangeHandler(ConnectionStatus status, ConnectionStatusChangeReason reason)
    {
        Console.WriteLine("Connection Status Changed to {0}; the reason is {1}",
          status, reason);
    }

    // This Task is never fired when using Device SDK 1.29.0-preview-004
    private static async Task OnDesiredPropertyChanged(TwinCollection desiredProperties, object userContext)
    {
        Console.WriteLine("desired property change:");
        Console.WriteLine(JsonConvert.SerializeObject(desiredProperties));
        Console.WriteLine("Sending current time as reported property");
        TwinCollection reportedProperties = new TwinCollection
        {
            ["DateTimeLastDesiredPropertyChangeReceived"] = DateTime.Now
        };

        await Client.UpdateReportedPropertiesAsync(reportedProperties).ConfigureAwait(false);
    }

Console log of the issue:


AB#7281154

IoTSDK bug fix-checked-in

All 10 comments

This is a known issue over AMQP. The latest preview version of our SDK includes a service API version update, which modifies the behavior of how desired property updates need to be subscribed for, over Amqp. We have a fix for this on our master branch, which we will bring over to the preview branch as well, soon.
In the meanwhile, you should still be able to get these property updates over Mqtt.

The fix for this issue has been checked in, and will be released soon. I'll update this thread once it is released

By when we can expect the release ?

We are planning to have this released by the end of this week.

Hi Team:
Is new SDK released ?

any possibility of getting a 1.29-preview-005 with device streams?

We are aiming to get a new preview version released with this fix by 6/17

Is 1.29-preview-005 released ?

This has been released as a part of Microsoft.Azure.Devices.Client.1.29.1-preview-001: https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/preview_2020-7-13.
Closing this issue.

@Feiko, @abhipsaMisra, @timtay-microsoft, @Harsh-m-Mehta, @billscottboston, thank you for your contribution to our open-sourced project! Please help us improve by filling out this 2-minute customer satisfaction survey

Was this page helpful?
0 / 5 - 0 ratings