Azure Function App CosmosDbTrigger给出了空参数错误

时间:2019-03-01 21:56:56

标签: azure-functions azure-cosmosdb cosmosdbtrigger

我正在定义如下的Azure功能应用程序:

public static void Run(
            [CosmosDBTrigger(
            databaseName: "dbName",
            collectionName: "collectiontoMonitor",
            ConnectionStringSetting = "collectionConnectionStringSettingName",
            LeaseDatabaseName = "LeaseDBName",
            LeaseCollectionName = "LeaseCollection",
            LeaseConnectionStringSetting = "LeaseConnectionString",
            LeaseCollectionPrefix ="funcName")]IReadOnlyList<Document> input, ILogger log)
        {
..
}

我正在从Visual Studio发布,并且可以正常运行。但是,即使在Collection中进行更改后,也永远不会触发该功能。 如果我手动运行该函数,则会出现错误:

Value cannot be null. Parameter name: o

上面是确切的错误消息,我没有名称为'o'的任何参数。我可能会错过什么?

更新:如果有所不同,Function App的订阅不同于Cosmos。

1 个答案:

答案 0 :(得分:1)

好吧,我终于通过请求创建租赁集合(如果尚不存在)来为我工作。以前,我是手工创建的,很可能配置不正确。删除租约集合并要求创建它(如果不存在)后,我看到它已正确创建并且问题已解决。

更改为:

public static void Run(
            [CosmosDBTrigger(
            databaseName: "dbName",
            collectionName: "collectiontoMonitor",
            ConnectionStringSetting = "collectionConnectionStringSettingName",
            LeaseDatabaseName = "LeaseDBName",
            LeaseCollectionName = "LeaseCollection",
            LeaseConnectionStringSetting = "LeaseConnectionString",
            CreateLeaseCollectionIfNotExists = true, // Add this line
            LeaseCollectionPrefix ="funcName")]IReadOnlyList<Document> input, ILogger log)
        {
..
}