'How to set User Agent string in MSGraph .net SDK

I'm reading customer email accounts using the MSGraph SDK v4.27.0 in C#. It works fine but one customer insists on using allowlists for EWS access to email. That grants access to apps that supply a User Agent string but how do I include it in the MSGraph header using the SDK calls?
The code is taken from the MS example

var scopes = new[] { "User.Read","Mail.ReadWrite","Mail.ReadWrite.Shared" };

var options = new TokenCredentialOptions
            {
                AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
            };

var userName = strAccount;

var password = strPWD ;


var userNamePasswordCredential = new UsernamePasswordCredential(
                userName, password, tenantId, theClientId, options);


var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);

try
{
   rootFolder = await graphClient.Me.MailFolders["msgfolderroot"]
               .Request()
               .GetAsync();
}..


Solution 1:[1]

Found the answer from the GitHubs docs eventually although it did take some experimentation finding out that the header option name is "User-Agent" You create an options list and add in the user agent option

 List<Option> theOptions = new List<Option>();
        theOptions.Add(new HeaderOption("User-Agent", "MyUserAgentName"));

Then every .Request() call has to have the options as a parameter e.g.

 rootFolder = await graphClient.Me.MailFolders["msgfolderroot"]
                .Request(theOptions)
                .GetAsync();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MisterA