Why did azure graph service client start to throw different exceptions?

Marcin Zapadka 1 Reputation point
2021-04-21T09:46:15.773+00:00

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?

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

1 answer

Sort by: Most helpful
  1. Shweta Choudhary 601 Reputation points Microsoft Employee
    2021-05-05T13:42:32.18+00:00

    While trying to use graph service client to add/update user, below screenshot mentions the behavior in case user doesn’t exist.

    94021-exception-debug.png

    93993-exception.png

    If we notice Error block, Code ‘Request_ResourceNotFound’ clearly states that requested user is not found.

    Unfortunately, I am not able to repo the scenario where object reference Null exception is thrown.
    Couple of things to check here –

    1. Make sure you are using updated version of SDK.
    2. Check if NULL exception you are getting is because of some code. Isolate the call from code and check the behavior.
    3. Check how exception is handled/thrown from catch.

    Let me know if this helps 😊

    0 comments No comments