microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Create Event: sending null for optional params returns nonspecific error

Open
#2,860 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Status: Needs investigation type:bug
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

Describe the bug

I am using the C# nuget package to post a calendar event. version 5.73 and .NET 8

await graphClient.Users[senderAddress] .Calendar .Events .PostAsync(newCalendarEvent);

where newCalendarEvent is type Event

The Event class defaults List properties to null rather than empty list as they are nullable, and so in the payload request that gets generated, they are null. As far as I can tell GetFieldDeserializers() also will return null rather than falling back on an empty list.

"Attachments": null,

This results in the following error

"Exception":"Microsoft.Graph.Models.ODataErrors.ODataError: were unable to deserialize \n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.ThrowIfFailedResponseAsync(HttpResponseMessage response, Dictionary2 errorMapping, Activity activityForAttributes, CancellationToken cancellationToken)\n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)\n at Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.SendAsync[ModelType](RequestInformation requestInfo, ParsableFactory1 factory, Dictionary2 errorMapping, CancellationToken cancellationToken)\n at Microsoft.Graph.Users.Item.Calendar.Events.EventsRequestBuilder.PostAsync(Event body, Action1 requestConfiguration, CancellationToken cancellationToken)\n ....

I've found that for various missing fields I either get this or a 500 "The operation failed" - instead of any sort of 400 validation messages.

So I had to guess and check a bunch of fields, and manually set them to empty list in order for my payload to go through.

Expected behavior

I would expect to receive a clear validation response detailing what fields are required or what is wrong with the payload format. If the fields are optional, they should not break when sent as null.

How to reproduce

Using a .NET 8 Web API project. Nullable context is not enabled.

Instantiate an empty event: Event newCalendarEvent = new Event();

Set the following fields with valid data:

  • IsOnlineMeeting
  • IsOrganizer
  • OnlineMeetingProvider
  • Subject
  • Start
  • End
  • IsReminderOn
  • ReminderMinutesBeforeStart
  • AllowNewTimeProposals
  • Attendees

Post the payload using a GraphServiceClient

await graphClient.Users[senderAddress]
.Calendar
.Events
.PostAsync(newCalendarEvent);

SDK Version

5.73

Latest version known to work for scenario above?

No response

Known Workarounds

I had to guess and check a bunch of fields, and manually set them to empty list in order for my payload to go through.

Debug output
Click to expand log ```
</details>


### Configuration

_No response_

### Other information

_No response_

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

Reproduce the issue in a .NET 8 Web API project by creating an empty Event, setting the listed fields, and posting it with GraphServiceClient. Inspect the generated payload and response handling around null optional list properties. Done means the request produces a specific validation response or null optional fields no longer cause the nonspecific deserialization or 500 error.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.