azure-functionsazure-cosmosdbcosmosdbtrigger

Azure Function App CosmosDbTrigger Gives Null Parameter Error


I am defining an Azure Function App as follows:

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

I am publishing from visual studio and it works without any errors. However, the Function is never triggered even after changes in the Collection. If I run the function manually, I get error:

Value cannot be null. Parameter name: o

The above is the exact error message and I don't have any parameter by the name 'o'. What could I be missing.

Update: In case it makes a difference, the Function App is under a different subscription than the Cosmos.


Solution

  • Ok, I finally got it working for me by requesting to create the lease collection if it isn't existing already. Previously, I hand created it and most likely wasn't configuring it properly. Once I deleted the lease collection and requested it to be created if not exist, I saw it was created properly and my issue was resolved.

    Change would be:

    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)
            {
    ..
    }