2

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.

Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
  • Do you have the rest of the stack trace? – Chris Anderson Mar 01 '19 at 22:03
  • Have you checked if you connection strings are set properly? – Chris Anderson Mar 01 '19 at 22:05
  • They are defined in the AppSettings. I checked few times and they look correct. – Shamim Hafiz - MSFT Mar 01 '19 at 22:06
  • @ChrisAnderson-MSFT BTW, they are under different subscription. – Shamim Hafiz - MSFT Mar 01 '19 at 22:15
  • 2
    You cannot run the Function manually, this is a Trigger that runs whenever there is a change in the collection. Running the Function manually works for things like HttpTrigger. The error you are seeing is because, when you use the Run in the Functions Portal, you re not sending the expected batch of Documents. Did you define the `LeaseConnectionString` AND `collectionConnectionStringSettingName` in the `App Settings`? Do you have ANY other Function running with the exact same configuration (locally or in the cloud)? – Matias Quaranta Mar 01 '19 at 23:08
  • @MatiasQuaranta Yes, I defined them in the Appsettings. There is another function with almost same parameter except it's on a different collection. – Shamim Hafiz - MSFT Mar 02 '19 at 00:53

1 Answers1

3

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)
        {
..
}
Shamim Hafiz - MSFT
  • 21,454
  • 43
  • 116
  • 176
  • 3
    These kind of issues often appear in your Function logs. If you use Application Insights you can check the `traces` where any issue with any Function initialization should appear. For this case, you might have encountered a message regarding an error on the leases collection. – Matias Quaranta Mar 04 '19 at 16:18