azure - CosmosDB触发器 : Object reference not set to an instance of an object

标签 azure azure-cosmosdb azure-functions

当我尝试使用 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);
                }
            }

        }
    }

enter image description here

最佳答案

更新您的 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/

相关文章:

visual-studio - 我们没有针对 Visual Studio Online 的区域特定数据中心吗

azure - 预编译的 Azure 函数行为异常

Azure Functions ServiceBus 触发缩放行为

azure - 无服务器微服务(Lambda 或函数)

reactjs - 无法使用 Azure Pipeline 在应用服务上部署 Nextjs 应用程序

azure - 无法使用 powershell 向 azure 进行身份验证

javascript - DocumentDB REST API 与 Postman 输出始终为 "Unauthorized"错误

Azure Cosmos DB 预触发器

c# - Azure Function 和 Docker 出现错误

Azure Webapp - Azure .Net SDK - 设置站点 IP 限制