microsoft-graph-devx-api icon indicating copy to clipboard operation
microsoft-graph-devx-api copied to clipboard

Documented C# SDK usage for assigning CSAs does not work

Open rolyon opened this issue 2 years ago • 2 comments

Describe the bug Documented C# SDK usage for assigning custom security attribute did not work

To Reproduce The following code example did not work https://learn.microsoft.com/en-us/graph/custom-security-attributes-examples?tabs=csharp#example-3-assign-a-custom-security-attribute-with-a-multi-string-value-to-a-user

Expected behavior Used this code instead var dict = new Dictionary<string, object> { { "@odata.type", "#microsoft.graph.customSecurityAttributeValue" }, { [email protected], "#Collection(String)" }, { "Programs", new string[] { "Baker", "Cascade" } } };

var attribute = JsonSerializer.SerializeToElement(dict);

var user = new User { CustomSecurityAttributes = new CustomSecurityAttributeValue { AdditionalData = new Dictionary<string, object>() { { "JadeAttributes", attribute } } } };

await _graphClient.Users[userId] .PatchAsync(user);

Screenshots

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context

rolyon avatar Sep 11 '23 19:09 rolyon

Hi @andrueastman Can you review this feedback? Let me know if I didn't submit correctly. thanks

rolyon avatar Sep 11 '23 20:09 rolyon

Thanks for raising this @rolyon

After investigation, it looks like the snippet generator is causing the issue here as the anonymous "Engineering" type is generated incorrectly causing incorrect serialization of the properties with special characters (i.e. @odata.type and [email protected]) hence the error.

andrueastman avatar Sep 22 '23 07:09 andrueastman

@andrueastman will this fix the code generated for other languages (python,java) as well?

asifbhat184 avatar Aug 01 '24 06:08 asifbhat184