【发布时间】:2019-09-18 09:19:02
【问题描述】:
我是 Azure Function 的新手,在我的第一个函数中我使用的是 CosmosDB。在引擎盖下,函数完美地完成了它的工作,但是当我在门户中打开我的函数时,我收到了这个错误。
函数 (LOANGILITY-AZFUNCTION/ProductDetailsFunc) 错误: Microsoft.Azure.WebJobs.Host:索引方法错误 'ProductDetailsFunc'。 Microsoft.Azure.WebJobs.Host:无法绑定 参数“文档”以键入 IAsyncCollector`1。确保 绑定支持参数类型。如果您使用绑定 扩展(例如 Azure 存储、ServiceBus、计时器等)确保 您已经调用了您的扩展程序的注册方法 启动代码(例如 builder.AddAzureStorage()、builder.AddServiceBus()、 builder.AddTimers() 等)。
我的函数头原型是
public static async Task<HttpResponseMessage> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)]HttpRequestMessage req,
[DocumentDB(
databaseName: "OB",
collectionName: "ProductDetails",
ConnectionStringSetting = "DBConnection")]IAsyncCollector<dynamic> document,
TraceWriter log)
从我的代码生成的 json 是
{
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.13",
"configurationSource": "attributes",
"bindings": [
{
"type": "httpTrigger",
"methods": [
"get",
"post"
],
"authLevel": "anonymous",
"name": "req"
}
],
"disabled": false,
"scriptFile": "../bin/Loangility01.dll",
"entryPoint": "Loangility01.ProductDetailsFunc.Run"
}
我还看到其他一些 SO 问题,他们在代码中谈论 builder.something,而我没有使用 .Net Core Azure Function,我的目标项目框架是 4.6.1。
【问题讨论】:
-
你使用的是Azure Function V1.0吗?
-
是的,我正在使用 v1
-
您想使用 Azure Cosmos DB 作为输入或输出绑定吗?
-
朋友是的,我在我的天蓝色函数中使用 cosmos db,它基本上是输出绑定,甚至我成功地将我的数据保存在 cosmos db 中。唯一的问题是我在门户中遇到了这个错误。
标签: c# azure azure-functions azure-cosmosdb