At the moment we are struggling with the API connection used by the Microsoft Graph SDK for C#.
I can't find any code which should generate a System.StackOverflowException
and the calls that the SDK makes work most times and sometimes it just gives the exception.
The SDK is used in a Console Application (.NET Framework 4.7.2) and uses version 4.48 at this point.
Below an example of the initiation of the GraphServiveClient
.
// Create builder
var confidentialClient = ConfidentialClientApplicationBuilder
.Create(Config.GraphClientId)
.WithAuthority($"https://login.microsoftonline.com/{Config.GraphTenantId}/v2.0")
.WithClientSecret(Config.GraphClientSecret)
.Build();
// Use the static GraphClientFactory to get the default pipeline
var handlers = GraphClientFactory.CreateDefaultHandlers(new DelegateAuthenticationProvider(async (requestMessage) =>
{
// Retrieve an access token for Microsoft Graph (gets a fresh token if needed).
var authResult = await confidentialClient
.AcquireTokenForClient(new[] { "https://graph.microsoft.com/.default" })
.ExecuteAsync();
// Add the access token in the Authorization header of the API request.
requestMessage.Headers.Add("Authorization", "Bearer " + authResult.AccessToken);
requestMessage.Version = new Version(1, 1);
}));
// Create HTTP client
var httpClient = GraphClientFactory.Create(handlers);
// Create client
GraphClient = new GraphServiceClient(httpClient);
One of the problems that I'm facing right now is that an email won't be send. The code is as follows:
// Send mail to the administration
await GraphClient.Users["email address removed for privacy reasons"].SendMail(new GraphMessage
{
ToRecipients = new Recipient[] { new Recipient { EmailAddress = new EmailAddress { Address = "email address removed for privacy reasons" } } },
Subject = $"Nieuwe aanmeldingen {DateTime.Now:dd-MM-yyyy}",
Body = new ItemBody
{
Content = template,
ContentType = BodyType.Html
}
}).Request().PostAsync();
When executing the code right after creating the GraphServiceClient it sends the mail perfectly, but when executing it further along in the code it gives an StackOverflowException.
I've tried to remove the RetryHandler which is default in the GraphServiceClient, disabling server certificate validation, different versions of the SDK. Execute it asynchronous, execute it synchronous.
All without success