0

我正在尝试使用 cosmos DB 输入绑定创建一个 Azure 函数 HttpTrigger。但它给了我一个类型错误。

Http 触发器

这是我正在尝试的:

public static async Task<IActionResult> Run(IReadOnlyList<Document> inputDocs, HttpRequest req, IAsyncCollector<Document> outputDocs, ILogger log)
{
}

它给了我以下错误:

2019-06-03T06:48:35.646 [Error] Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.HttpTrigger1'. Microsoft.Azure.WebJobs.Host: Can't bind CosmosDB to type 'System.Collections.Generic.IReadOnlyList`1[Microsoft.Azure.Documents.Document]'.
Possible causes:
1) Tried binding to 'Microsoft.Azure.Documents.Client.DocumentClient, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
2) Tried binding to 'Newtonsoft.Json.Linq.JArray, Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.
3) Tried binding to 'System.Collections.Generic.IEnumerable`1[[Microsoft.Azure.WebJobs.Extensions.CosmosDB.CosmosDBExtensionConfigProvider+DocumentOpenType, Microsoft.Azure.WebJobs.Extensions.CosmosDB, Version=3.0.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' but user type assembly was 'System.Collections.Generic.IReadOnlyList`1[[Microsoft.Azure.Documents.Document, Microsoft.Azure.DocumentDB.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e.

任何人都可以帮我输入类型吗?

4

1 回答 1

2

有关您正在做的事情的示例,请参见此处:https ://docs.microsoft.com/en-us/sandbox/functions-recipes/cosmos-db?tabs=csharp#retrieve-a-list-of-文件

[FunctionName("CosmosDBSample")]
public static HttpResponseMessage Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequestMessage req,
    [DocumentDB("test", "test", ConnectionStringSetting = "CosmosDB", sqlQuery = "SELECT top 2 * FROM c order by c._ts desc")] IEnumerable<object> documents)
{
    return req.CreateResponse(HttpStatusCode.OK, documents);
}
于 2019-06-03T07:18:26.033 回答