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 Users API
Microsoft Graph Users API
A Microsoft API that allows you to build compelling app experiences based on users, their relationships with other users and groups, and the resources they access for example their mails, calendars, files, administrative roles, group memberships.
547 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
733 questions
Microsoft Graph Identity API
Microsoft Graph Identity API
A Microsoft API to access Azure Active Directory (Azure AD) resources to enable scenarios like managing administrator (directory) roles, inviting external users to an organization, and, if you are a Cloud Solution Provider (CSP), managing your customer's data.
257 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Shweta Choudhary 591 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 😊

    No comments