Why am I unable to set CustomSecurityAttributes on an AAD User in C# using Microsoft.Graph.Beta?

Kyle Flick 0 Reputation points

I have an attribute set named "TestSet" with the attribute "TestString". When attempting to set this attribute value as follows, an ODataError is thrown with Error.Message "Invalid property 'TestSet'.". However, I am able to set these values via the Azure UI.

if (!string.IsNullOrWhiteSpace(user.Degree))
    var patch = new User();
    patch.CustomSecurityAttributes ??= new CustomSecurityAttributeValue();

    patch.CustomSecurityAttributes.AdditionalData.Add("TestSet", new
        OdataType = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
        TestString = user.Degree,

    await _client.Users[newUserId].PatchAsync(patch);
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,581 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Kyle Flick 0 Reputation points

    The issue is with how "OdataType" is serialized in JSON. Microsoft needs to update their documentation for this as what they have does not work.

    0 comments No comments