当我尝试使用 CosmosDBTrigger 执行新创建的 azure 函数时,使用 cosmosdb 触发器的函数出现上述异常
调查信息
环境: Visual Studio 2017 15.3.5
引用的包:
- Marvin.JsonPatch.Dynamic 版本=“1.1.0”
- Microsoft.Azure.DocumentDB 版本=“1.17.0”
- Microsoft.Azure.WebJobs 版本=“2.1.0-beta4”
- Microsoft.Azure.WebJobs.Extensions.DocumentDB 版本="1.1.0-beta4"
- Microsoft.Azure.WebJobs.ServiceBus 版本=“2.0.0”
- Microsoft.NET.Sdk.Functions 版本=“1.0.5”
- Newtonsoft.Json 版本=“10.0.3”
- System.Configuration.ConfigurationManager版本=“4.4.0”
重现问题的步骤
提供重现问题所需的步骤:
- 从 Visual Studio 创建新的 Azure Function 项目
- 添加一个函数(我没有找到任何 CosmosDB 绑定(bind)选项,所以我使用 HttpTrigger 创建) 创建 .cs 文件后,用我在下面放置的代码替换该文件。
- 构建
- 按 F5
这是代码示例
public static class AddEventInEventStore
{
[FunctionName("AddEventInEventStore")]
public static void Run([CosmosDBTrigger("db", "Items",
ConnectionStringSetting = "AzureWebJobsDocumentDBConnectionString",
LeaseCollectionName = "leases", LeaseDatabaseName = "db"
)]
IReadOnlyList<Document> changeList, TraceWriter log)
{
if (changeList != null && changeList.Count > 0)
{
log.Verbose("Documents modified " + changeList.Count);
foreach (var change in changeList)
{
log.Verbose("First document Id " + change.Id);
}
}
}
}
最佳答案
更新您的 Azure Functions 和 Web 作业工具(工具 -> 扩展和更新)。
我可以看到您使用的是 1.0.0
版本(控制台标题),而 1.0.4
已经可用。
关于azure - CosmosDB触发器 : Object reference not set to an instance of an object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46559852/