C# 无法使用Microsoft Graph SDK上载文件

C# 无法使用Microsoft Graph SDK上载文件,c#,microsoft-graph-api,microsoft-graph-sdks,C#,Microsoft Graph Api,Microsoft Graph Sdks,我正在尝试使用Microsoft的Graph SDK上载文件,但遇到了一个问题 我几乎一字不差地复制了C#示例,注释了进度部分,并使用C#8的语句更新了,下面是我所做的 public async Task<bool> UploadFileAsync(string parentFolderId, string filename, byte[] bytes) { var graphClient = GetGraphClient(); // Declare the var

我正在尝试使用Microsoft的Graph SDK上载文件,但遇到了一个问题

我几乎一字不差地复制了C#示例,注释了进度部分,并使用C#8的语句更新了
,下面是我所做的

public async Task<bool> UploadFileAsync(string parentFolderId, string filename, byte[] bytes)
{
    var graphClient = GetGraphClient();

    // Declare the variable outside the `using` statement to get around a little C# problem - https://www.tabsoverspaces.com/233779-using-await-using-iasyncdisposable-with-configureawait
    var memoryStream = new MemoryStream(bytes);
    await using (memoryStream.ConfigureAwait(false))
    {
        // Use properties to specify the conflict behavior.
        // - in this case, replace.
        var uploadProps = new DriveItemUploadableProperties
                          {
                              AdditionalData = new Dictionary<string, object> {{"@microsoft.graph.conflictBehavior", "replace"}},
                              ODataType = null
                          };
        try
        {
            // Create the upload session.
            // - itemPath does not need to be a path to an existing item.
            var uploadSession = await graphClient.Drives[_driveId]
                                                 .Items[parentFolderId]
                                                 .ItemWithPath(filename)
                                                 .CreateUploadSession(uploadProps)
                                                 .Request()
                                                 .PostAsync()
                                                 .ConfigureAwait(false);

            // Max slice size must be a multiple of 320KB.
            const int maxSliceSize = 320 * 1024;
            var fileUploadTask = new LargeFileUploadTask<DriveItem>(uploadSession, memoryStream, maxSliceSize);

            // Upload the file.
            var uploadResult = await fileUploadTask.UploadAsync().ConfigureAwait(false);

            if (uploadResult.UploadSucceeded)
            {
                // The ItemResponse object in the result represents the created item.
                return true;
            }

            return false;
        }
        catch (ServiceException exception)
        {
            // ...
        }
    }
}
…引发异常:

Microsoft.Graph.ServiceException:代码:BadRequest 消息:“microsoft.graph.createUploadSession”的多个操作重载具有相同的绑定参数


有人能帮忙吗?

我找到了问题的原因-我使用的文件名包含无效符号(在我的例子中,我是在串接日期时间,其中包含

令人沮丧的是,这个异常没有正确出现,相反,我得到了“多动作重载”的消息

var uploadSession = await graphClient.Drives[_driveId]
                                     .Items[parentFolderId]
                                     ...