I found the solution here:
https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet/issues/616
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
After having problems with reading custom security attribute which I've solved by using Microsoft.Graph.Beta 5.22, I ran into the next problem.
If I try to update the value of a custom security attribute (like in https://learn.microsoft.com/en-us/graph/custom-security-attributes-examples?tabs=csharp) I get the following error message:
Request_BadRequest
Invalid property 'CsasAXCustomerData'.
Microsoft.Graph.Beta.Models.ODataErrors.ODataError: Exception of type 'Microsoft.Graph.Beta.Models.ODataErrors.ODataError' was thrown.
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponse(HttpResponseMessage response, Dictionary`2 errorMapping, Activity activityForAttributes)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory`1 factory, Dictionary`2 errorMapping, CancellationToken cancellationToken)
at Microsoft.Graph.Beta.Users.Item.UserItemRequestBuilder.PatchAsync(User body, Action`1 requestConfiguration, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in C:\Projects\TestGraph\TestGraph\Program.cs:line 50
Here ist the code I use:
using Azure.Identity;
using Microsoft.Graph.Beta;
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph.Beta.Models.ODataErrors;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Reflection;
using TestGraph;
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "<tenantid>";
var clientId = "<clientid>";
var clientSecret = "<clientSecret>;
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret, options);
var client = new GraphServiceClient(clientSecretCredential, scopes);
string userid = "<userid>";
try
{
var requestBody = new User
{
CustomSecurityAttributes = new CustomSecurityAttributeValue
{
AdditionalData = new Dictionary<string, Object>
{
{
"CsasAXCustomerData", new
{
OdataType = "#Microsoft.DirectoryServices.CustomSecurityAttributeValue",
CsaAXDataAreaId = "xxx",
}
}
}
}
};
await client.Users[userid].PatchAsync(requestBody);
}
catch(ODataError odataError)
{
Console.WriteLine(odataError.Error.Code);
Console.WriteLine(odataError.Error.Message);
Console.WriteLine(odataError.ToString());
}
CsasAXCustomerData is a Custom Security Attribute Set, CsaAXDataAreaId is a Custom Security Attribute with type of string.
The app registration has assigned the following API permissions:
I found the solution here:
https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet/issues/616