Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug Report] TwinCollection.ClearMetadata does not clean metadata for properties #1971

Closed
florianbader opened this issue May 19, 2021 · 3 comments
Assignees
Labels
bug Something isn't working. fix-checked-in Fix checked into main or preview, but not yet released. IoTSDK Tracks all IoT SDK issues across the board

Comments

@florianbader
Copy link

florianbader commented May 19, 2021

Context

  • OS, version, SKU and CPU architecture used: Win 10 Desktop x64 (Windows 10 Desktop x64, Ubuntu 15.04 x86, Windows 10 IoT Core arm32, etc.)
  • Application's .NET Target Framework : .NET 5 (See https://docs.microsoft.com/en-us/dotnet/standard/frameworks. E.g. netcoreapp2.1, net451, uap10.0, xamarin)
  • Device: : Laptop (Laptop, Raspberry PI3, Android APIv25 etc.)
  • SDK version used: Microsoft.Azure.Devices 1.30.0 (Please include the NuGet package version for all involved components)

Description of the issue

Using the GetTwin method from RegistryManager returns the TwinProperties as TwinCollection. If using ClearMetadata on the TwinCollection for e.g. the desired properties it will not clear the metadata for the properties. Because of that if accessing a property afterwards it will return a TwinCollection instead of a JObject in the TryGetMemberInternal method. This is unexpected because after clearing the metadata I would expect a JObject which causes a RuntimeBindingException.

Code sample exhibiting the issue

var twin = await registryManager.GetTwinAsync("device");
twin.Properties.Desired.ClearMetadata();
twin.Properties.Desired["property"].GetType() // expected JObject, got TwinCollection

Current workaround which is really ugly is this:

var twin = await registryManager.GetTwinAsync("device");
twin.Properties.Desired.ClearMetadata();
var twinPatch = new Twin(new TwinProperties { Desired = new TwinCollection(twin.Properties.Desired.ToJson()) });
twin.Properties.Desired["property"].GetType() // returns JObject
@florianbader florianbader added the bug Something isn't working. label May 19, 2021
@github-actions github-actions bot added the IoTSDK Tracks all IoT SDK issues across the board label May 19, 2021
@jamdavi
Copy link
Member

jamdavi commented May 19, 2021

Hey @florianbader,

I was able to reproduce the same behavior. I see a way around this by separating the metadata JObject from the payload JObject. Let me reach out to the team internally to see if there is any negative implications to doing this.

@jamdavi jamdavi self-assigned this May 20, 2021
jamdavi added a commit that referenced this issue May 29, 2021
…win and the base metadata object (#1976)

Addressing issue #1971 where a customer wants to be able to use the TwinCollection from a non device client to get a raw JObject instead of a TwinCollection.
@jamdavi jamdavi added the fix-checked-in Fix checked into main or preview, but not yet released. label May 29, 2021
@jamdavi
Copy link
Member

jamdavi commented May 29, 2021

@florianbader We have added a new method called ClearAllMetadata this is a more extensive method that destroys the underlying metadata object and will have the desired effect you're looking for. I'll leave this issue open and update when we make a new release.

@abhipsaMisra
Copy link
Member

This feature has been released in our latest release: https://github.com/Azure/azure-iot-sdk-csharp/releases/tag/2021-8-11
Closing this issue.

timstewartm pushed a commit to timstewartm/azure-iot-sdk-csharp that referenced this issue May 30, 2024
…win and the base metadata object (Azure#1976)

Addressing issue Azure#1971 where a customer wants to be able to use the TwinCollection from a non device client to get a raw JObject instead of a TwinCollection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working. fix-checked-in Fix checked into main or preview, but not yet released. IoTSDK Tracks all IoT SDK issues across the board
Projects
None yet
Development

No branches or pull requests

3 participants