microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

[Client bug]: Nullable Reference Types are misleading

Open
#1,739 9 comments 17 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Request: enhancement
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

Describe the bug
Properties are marked as nullable which should never be null.

To Reproduce
Consider the following method and assume I have <Nullable>enable</Nullable> set in my .csproj file:

private async Task<List<MailFolder>> GetMailFolders(UserItemRequestBuilder user)
{
    var folders = await user.MailFolders.GetAsync();
    return folders.Value;
}

When building, I get two nullability warnings, CS8602 (folders might be null) and CS8603 (folders.Value might be null). The first one I could understand. Something went wrong with the request so the response is null. The second, however, I have a hard time wrapping my head around. Collection data structures should rarely be null. In the case something went wrong, they are often simply empty. I looked into the SDK code and saw that pretty much every property is marked as nullable, even properties which can never be null, like an Id. This doesn't help the developer at all. I just upgraded from v4 to v5 and my build is now littered with incorrect nullability warnings.

Expected behavior
Only properties which actually can be null, are marked as nullable.

Client version
5.2.0

Desktop (please complete the following information):

  • OS: macOS
  • Version: Ventura (13.2.1)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the nullable warnings in the GetMailFolders example with Microsoft Graph SDK v5.2.0, then inspect the generated SDK properties involved in the response and model types. Done means properties that cannot be null no longer produce incorrect nullable warnings while genuinely nullable properties remain annotated.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.