【问题标题】:Azure Function App CosmosDbTrigger Gives Null Parameter ErrorAzure Function App CosmosDbTrigger 给出空参数错误
【发布时间】:2019-03-01 21:56:55
【问题描述】:

我正在定义一个 Azure Function App,如下所示:

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 的订阅不同。

【问题讨论】:

  • 你有剩余的堆栈跟踪吗?
  • 您是否检查过您的连接字符串是否设置正确?
  • 它们在 AppSettings 中定义。我检查了几次,它们看起来是正确的。
  • @ChrisAnderson-MSFT BTW,他们在不同的订阅下。
  • 你不能手动运行函数,这是一个触发器,只要集合发生变化就会运行。手动运行函数适用于 HttpTrigger 之类的东西。您看到的错误是因为当您在 Functions Portal 中使用 Run 时,您没有发送预期的文档批次。您是否在App Settings 中定义了LeaseConnectionStringcollectionConnectionStringSettingName?您是否有任何其他功能以完全相同的配置运行(本地或云中)?

标签: azure-functions azure-cosmosdb cosmosdbtrigger


【解决方案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)
        {
..
}

【讨论】:

  • 这类问题经常出现在您的函数日志中。如果您使用 Application Insights,您可以检查traces,其中应该出现任何函数初始化问题。对于这种情况,您可能会遇到有关租约集合错误的消息。
猜你喜欢
  • 1970-01-01
  • 2022-10-04
  • 2021-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多