3

I am using azure graph service client to add/update users and groups in Office365. I relied on its exceptions which were of type ServiceException and contained status code and message, which I used to determine what to do next with this result.

It worked well, because when I tried to retrieve user I simply used graphClient.Users[email].Request().GetAsync() and I got ServiceException with status of 'NotFound' I knew that user does not exist and what should I do about.

Unfortunately now it has changed and when user does not exist I get System.Exception with following message Object reference not set to an instance of an object.

I'm guessing that it still means that user was not found, but it could also mean something different so my custom logic might break if I catch it and treat it like user does not exist.

Does anybody know why it's like that? Did anything change lately with exceptions from graph client or is it temporar bug on graph service client side?

// UPDATE

Here's the code I used to create graph service client and run the method to retrieve a user:

var confidentialClientApplication = ConfidentialClientApplicationBuilder
                .Create("client_id")
                .WithTenantId("tenant_id")
                .WithClientSecret("client_secret")
                .Build();

var scopes = new[] { "https://graph.microsoft.com/.default" };
AuthenticationResult result = null;

try
{
    result = await confidentialClientApplication.AcquireTokenForClient(scopes).ExecuteAsync();
}
          
catch(Exception)
{                
    // error handling
}

var graphClient = new GraphServiceClient(
    new DelegateAuthenticationProvider(
        async (requestMessage) =>
        {                       
            requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", result.AccessToken);
        }));

var user = graphClient.Users["email"].Request().GetAsync();
Isard
  • 312
  • 1
  • 14
  • Actually, the `Request_ResourceNotFound` will return if the user-id/email does not exist. Please share more details like code and your azure settings when facing this error `Object reference not set to an instance of an object`. – unknown Apr 27 '21 at 07:38
  • I edited the post to include the code, but tbh there's not really much of it. I'm also not sure which azure settings would you like to see so I did not insert any. Speaking of `Request_ResourceNotFound` - it did return like this when email did not exist with the same configuration like I have right now. We did not change anything in code and suddenly it started to return `Object reference not set to an instance of an object` instead. – Isard Apr 27 '21 at 08:42

0 Answers0