CosmosDBTrigger:对象引用未设置为对象的实例
CosmosDBTrigger: Object reference not set to an instance of an object
当我尝试使用 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 Version="1.1.0-beta4"
- Microsoft.Azure.WebJobs.ServiceBus Version="2.0.0"
- Microsoft.NET.Sdk.Functions 版本="1.0.5"
- Newtonsoft.Json 版本="10.0.3"
- System.Configuration.ConfigurationManager 版本="4.4.0"
重现问题的步骤
提供重现问题所需的步骤:
- 从 Visual Studio
创建一个新的 Azure Functions 项目
- 添加功能(我没有找到 CosmosDB 绑定的任何选项,所以我使用 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
已经可用。
当我尝试使用 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 Version="1.1.0-beta4"
- Microsoft.Azure.WebJobs.ServiceBus Version="2.0.0"
- Microsoft.NET.Sdk.Functions 版本="1.0.5"
- Newtonsoft.Json 版本="10.0.3"
- System.Configuration.ConfigurationManager 版本="4.4.0"
重现问题的步骤
提供重现问题所需的步骤:
- 从 Visual Studio 创建一个新的 Azure Functions 项目
- 添加功能(我没有找到 CosmosDB 绑定的任何选项,所以我使用 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
已经可用。