Microsoft graph code general exception using Graph client in C#

SAC_535 36 Reputation points
2022-03-31T09:29:57.98+00:00

We are calling Graph client method to get user details and and message details but its not working.

code :

IConfidentialClientApplication app;
app = ConfidentialClientApplicationBuilder.Create("{client id}")
.WithClientSecret("{client secret}")
//.WithRedirectUri("https://jwt.ms")
.WithAuthority(new Uri("https://login.microsoftonline.com/{tenant id}"))
.Build();

         AuthenticationResult result;

         string[] scopes = new string[] { "https://graph.microsoft.com/.default" };

         result = await app.AcquireTokenForClient(scopes).ExecuteAsync();

         /*string accesstoken = result.AccessToken;

         Console.WriteLine(accesstoken);*/



         GraphServiceClient graphClient = new GraphServiceClient(authProvider);

         var message = await graphClient.Users["{user id}"].Messages["{message id}"]
 .Request()
 .GetAsync();

When we run application using visual studio 2-17 using C# its working fine without any error but when we deploy build files of application to the project folder location which is addin to outlook its not working and giving below exception

Exception : Code : generalException
Message : An error occurred sending the request

stack trace :
at Microsoft.Graph.HttpProvider.<SendRequestAsync>d__19.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

Cant understand what is exact root cause of this error and how to fix this.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,829 questions
{count} vote

1 answer

Sort by: Most helpful
  1. SAC_535 36 Reputation points
    2022-04-04T05:35:44.703+00:00

    @Vicky Kumar (Mindtree Consulting PVT LTD) Thanks for reply. We are using async call and in try catch its giving error generalException
    Message : An error occurred sending the request. Thus unable to figure out what is the error.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.