microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

CreateUploadSessionRequestBuilder.PostAsync fails with 400 status code when FileSystemInfo included

Open
#3,110 1 comment 0 reactions 1 assignee View on GitHub

@lramosvea is already working on this.

Since May 11, 2026.

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

Description

Describe the bug

I'm attempting to create a file upload session with pre-set FileSystemInfo using CreateUploadSessionRequestBuilder.

The request builder serializes the CreateUploadSessionPostRequestBody object into the following JSON:

{
  "item": {
    "fileSystemInfo": {
	  "createdDateTime": "2000-01-01T00:00:00-06:00",
	  "lastModifiedDateTime":"2000-01-01T00:00:00-06:00"
     },
     "@microsoft.graph.conflictBehavior":"replace"
  }
}

Which results in a 400 error when attempting to POST

Image
Expected behavior

Serialize the request body so that the "fileSystemInfo" property appears after the "@microsoft.graph.conflictBehavior" directive (which is what the graph API wants?!?) and the POST succeeds:

Image
How to reproduce
DateTime created = new DateTime(2000, 1, 1);

var uploadSessionRequestBody = new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody
{
    Item = new DriveItemUploadableProperties
    {
        AdditionalData = new Dictionary<string, object>
        {
            { "@microsoft.graph.conflictBehavior", "replace" },
        },
        FileSystemInfo = new Microsoft.Graph.Models.FileSystemInfo
        {
            CreatedDateTime = created,
            LastModifiedDateTime = created
        }
    }
};

var uploadSession = await graphClient.Drives[driveId]
    .Root
    .ItemWithPath(targetPath)
    .CreateUploadSession
    .PostAsync(uploadSessionRequestBody);
SDK Version

5.103.0

Latest version known to work for scenario above?

No response

Known Workarounds

Use "ToPostRequestInformation" to create a request object and manipulate the request body before sending:

        var uploadSessionRequestBody = new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody
        {
            Item = new DriveItemUploadableProperties
            {
                AdditionalData = new Dictionary<string, object>
                {
                    { "@microsoft.graph.conflictBehavior", "replace" },
                },
                FileSystemInfo = new Microsoft.Graph.Models.FileSystemInfo
                {
                    CreatedDateTime = created,
                    LastModifiedDateTime = created
                }
            }
        };

        var uploadSessionRequest = Graph.Drives[driveId]
            .Root
            .ItemWithPath(targetPath)
            .CreateUploadSession
            .ToPostRequestInformation(uploadSessionRequestBody);
       
        using (var reader = new StreamReader(uploadSessionRequest.Content))
        {
            var jsonString = await reader.ReadToEndAsync();
            JsonNode? rootNode = JsonNode.Parse(jsonString);

            if (rootNode != null && rootNode["item"] is JsonObject itemObj)
            {
                JsonNode? fileSystemInfoNode = itemObj["fileSystemInfo"];
                JsonNode? conflictBehaviorNode = itemObj["@microsoft.graph.conflictBehavior"];

                if (fileSystemInfoNode != null && conflictBehaviorNode != null)
                {
                    itemObj.Remove("fileSystemInfo");
                    itemObj.Remove("@microsoft.graph.conflictBehavior");
                    itemObj.Add("@microsoft.graph.conflictBehavior", conflictBehaviorNode);
                    itemObj.Add("fileSystemInfo", fileSystemInfoNode);
                }

                uploadSessionRequest.Content = new StringContent(rootNode.ToJsonString()).ReadAsStream();
            }
        }

        var uploadSession = await Graph.RequestAdapter.SendAsync(
            uploadSessionRequest, 
            UploadSession.CreateFromDiscriminatorValue, 
            new Dictionary<string, ParsableFactory<IParsable>>{{ "XXX", ODataError.CreateFromDiscriminatorValue }});
Debug output

No response

Configuration

No response

Other information

I'm not sure if this is an issue with the SDK because typically an API shouldn't care about the order in which JSON fields appear. I've seen examples of .net SDK code with upload sessions that include file system info so I'm not sure at which point this broke.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.