SharePoint List and Hyperlink field with Microsoft Graph results in "bad request

未关闭
#3,235 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
48/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
csharp

调研方向

The report includes a C# request that posts list item fields to the Microsoft Graph endpoint /sites/{siteId}/lists/{listId}/items, and says the request fails when linkPDF is included. Start by checking the documented Graph format for setting SharePoint hyperlink fields and compare it with the posted Url and Description object. Done means identifying whether the payload or SDK request handling causes the 400 and documenting a working approach.

由索引模型根据 Issue 内容生成。

描述

status:waiting-for-triage type:bug
Describe the bug

I'm trying to add a record to a SharePoint List with a Hyperlink field with Microsoft Graph but I get result "bad request" json payload is {
"fields": {
"Title": "TEST",
"linkPDF": {
"Url": "https://www.microsoft.com",
"Description": "Microsoft"
}
}
}
Code is:
var fields = new JObject
{
["Title"] = entry.Title,
["Maschine"] = entry.Maschine,
["Location"] = entry.Location,
["DocumentNr"] = Convert.ToString(entry.DocumentNr),
["DocumentType"] = entry.Documenttype,
["UploadTarget"] = entry.UploadTarget,
["Message"] = entry.Message,
["TargeteMail"] = entry.TargeteMail,
["PDF"] = entry.PDF
};
if (!string.IsNullOrWhiteSpace(entry.linkPDF))
{
//fields["linkPDF"] = new JObject
//{
// ["Url"] = entry.linkPDF,
// ["Description"] = string.IsNullOrWhiteSpace(entry.PDF) ? entry.linkPDF : entry.PDF
//};
fields["linkPDF"] = new JObject
{
["Url"] = "https://www.microsoft.com",
["Description"] = "Microsoft"
};
}
string json = new JObject { ["fields"] = fields }.ToString();
Globals.CWC($"json={json}", ConsoleColor.Yellow); // zum Prüfen
var request = new RequestInformation
{
HttpMethod = Method.POST,
URI = new Uri($"https://graph.microsoft.com/v1.0/sites/{_siteId}/lists/{_listId}/items")
};
request.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(json)), "application/json");
var errorMapping = new Dictionary<string, ParsableFactory>
{
{ "4XX", ODataError.CreateFromDiscriminatorValue },
{ "5XX", ODataError.CreateFromDiscriminatorValue }
};
try
{
await _graphClient.RequestAdapter.SendAsync(request, ListItem.CreateFromDiscriminatorValue);
}
catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)

Expected behavior

normal entry in the SharePoint list with a hyperlink field (without the hyperlink field everything went fine)

How to reproduce
var fields = new JObject
  {
    ["Title"] = entry.Title,
    ["Maschine"] = entry.Maschine,
    ["Location"] = entry.Location,
    ["DocumentNr"] = Convert.ToString(entry.DocumentNr),
    ["DocumentType"] = entry.Documenttype,
    ["UploadTarget"] = entry.UploadTarget,
    ["Message"] = entry.Message,
    ["TargeteMail"] = entry.TargeteMail,
    ["PDF"] = entry.PDF
  };
  if (!string.IsNullOrWhiteSpace(entry.linkPDF))
  {
    //fields["linkPDF"] = new JObject
    //{
    //  ["Url"] = entry.linkPDF,
    //  ["Description"] = string.IsNullOrWhiteSpace(entry.PDF) ? entry.linkPDF : entry.PDF
    //};
    fields["linkPDF"] = new JObject
    {
      ["Url"] = "https://www.microsoft.com",
      ["Description"] = "Microsoft"
    };
  }
  string json = new JObject { ["fields"] = fields }.ToString();
  Globals.CWC($"json={json}", ConsoleColor.Yellow);   // zum Prüfen
  var request = new RequestInformation
  {
    HttpMethod = Method.POST,
    URI = new Uri($"https://graph.microsoft.com/v1.0/sites/{_siteId}/lists/{_listId}/items")
  };
  request.SetStreamContent(new MemoryStream(Encoding.UTF8.GetBytes(json)), "application/json");
  var errorMapping = new Dictionary<string, ParsableFactory<IParsable>>
      {
        { "4XX", ODataError.CreateFromDiscriminatorValue },
        { "5XX", ODataError.CreateFromDiscriminatorValue }
      };
  try
  {
    await _graphClient.RequestAdapter.SendAsync(request, ListItem.CreateFromDiscriminatorValue);
  }
  catch (Microsoft.Graph.Models.ODataErrors.ODataError ex)
SDK Version

Graph 6.10 and Kiota 2.1.6

Latest version known to work for scenario above?

never had a running solution

Known Workarounds

no

Debug output
Click to expand log ``` Level 0 Type: System.AggregateException Message: Mindestens ein Fehler ist aufgetreten. StackTrace: bei System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) bei System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) bei System.Threading.Tasks.Task.Wait() bei e_invoicing.EInvoicingApp.Run(String[] args) in C:\VM\Kairo\e-invoicing\e-invoicing\EInvoicingApp.cs:Zeile 172. Level 1 Type: Microsoft.Kiota.Abstractions.ApiException Message: The server returned an unexpected status code and no error factory is registered for this code: 400 StackTrace: bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101. Assertion failed: System.AggregateException: Mindestens ein Fehler ist aufgetreten. ---> Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and no error factory is registered for this code: 400 bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101. --- Ende der internen Ausnahmestapelüberwachung --- bei System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) bei System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) bei System.Threading.Tasks.Task.Wait() bei e_invoicing.EInvoicingApp.Run(String[] args) in C:\VM\Kairo\e-invoicing\e-invoicing\EInvoicingApp.cs:Zeile 191. ---> (Interne Ausnahme #0) Microsoft.Kiota.Abstractions.ApiException: The server returned an unexpected status code and no error factory is registered for this code: 400 bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__32.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei Microsoft.Kiota.Http.HttpClientLibrary.HttpClientRequestAdapter.d__24`1.MoveNext() --- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() bei System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) bei System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei e_invoicing.SharePointLogger.d__4.MoveNext() in C:\VM\Kairo\e-invoicing\e-invoicing\SharepointLogger.cs:Zeile 101.<---
Configuration

Windows 11, newest release
x64

Other information

I've tried for 5 days now all different type of hyperlink within a sharepoint list. It works fine by entering the Hyperlink by hand, but I've never succeeded using c#

主要语言
C#
星标
796
派生
267
平均合并
1 天 4 小时
30 天内合并 PR
5

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoftgraph/msgraph-sdk-dotnet 的其他 Issue

查看 microsoftgraph/msgraph-sdk-dotnet 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。