microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
Duplicate Fields Serialized to Request Body When Set Explicitly to Null
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 789
- Forks
- 264
- Avg merge
- 15h 17m
- Merged PRs (30d)
- 3
Description
Describe the bug
I am using the GraphServiceClient class in some unit tests. Some unit tests populate fields on Graph contract objects with ternary statements (e.g. application.Description = condition ? "a description" : null). In the null cases here, I am observing the GraphServiceClient serialize the nulled field twice in the request body, which is causing JSON validation errors in my tests.
Expected behavior
Setting any field on the Application object explicitly to null and then using it in a GraphServiceClient request body serializes the object into valid JSON (without any duplicate fields).
How to reproduce
This code...
var appDisplayName = $"Application {guid}";
var application = new Application
{
DisplayName = appDisplayName,
Description = null,
IdentifierUris = new List<string> { $"urn:{appDisplayName}" },
};
var createdApplication = await this.graphClient.Applications.PostAsync(application);
...Sends this request body to the Graph service the client is pointed to:
{
"description":null,
"description":null,
"@odata.type":"#microsoft.graph.application",
"displayName":"Application f5b18965-f282-455b-9d0f-cc9d816cebcf",
"identifierUris":["urn:Application f5b18965-f282-455b-9d0f-cc9d816cebcf"]
}
This also happens with other fields in the Application class when set explicitly to null.
SDK Version
5.65.0
Latest version known to work for scenario above?
5.56.0
Known Workarounds
No response
Debug output
Click to expand log
```</details>
### Configuration
- OS: Windows 11
- architecture: x64
### Other information
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the request with GraphServiceClient and an Application whose Description is explicitly null, comparing the serialized body in versions 5.65.0 and 5.56.0. Trace the serialization path for Application fields and verify that the request body contains each explicitly null field only once while preserving the other shown fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100