Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Can't figure out which ctor to call." error with CosmosDB trigger #2447

Open
icanfathom opened this issue Feb 2, 2024 · 10 comments
Open

"Can't figure out which ctor to call." error with CosmosDB trigger #2447

icanfathom opened this issue Feb 2, 2024 · 10 comments

Comments

@icanfathom
Copy link

icanfathom commented Feb 2, 2024

I'm trying to run a new Function locally. It uses the CosmosDB trigger. Building works fine, but when trying to run with func host start, I get this error: The 'companiesWrite' function is in error: Unable to configure binding 'cosmosDBTrigger1' of type 'cosmosDBTrigger'. This may indicate invalid function.json properties. Can't figure out which ctor to call.

I see a similar issue here: #277. The problem was a misnamed configuration property. But I checked all of mine against both the TypeScript def and the online documentation.

My code:

import { app, InvocationContext } from "@azure/functions";

export async function companiesWrite(documents: any[], context: InvocationContext): Promise<void> {
    context.log(`Cosmos DB function processed ${documents.length} documents`);
}

app.cosmosDB('companiesWrite', {
    connectionStringSetting: 'devworksafetyindex_DOCUMENTDB',
    databaseName: 'wsi',
    collectionName: 'companies',
    createLeaseCollectionIfNotExists: true,
    maxItemsPerInvocation: 40,
    handler: companiesWrite
});

My host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Request"
      }
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[4.*, 5.0.0)"
  }
}

I tried adding an HttpTrigger Function, and this worked fine. So it appears to be something specific to my CosmosDB trigger.

Thanks!

@icanfathom icanfathom added the bug label Feb 2, 2024
@icanfathom icanfathom changed the title "Can't figure out which ctor to call." error with CosmosDB binding "Can't figure out which ctor to call." error with CosmosDB trigger Feb 2, 2024
@bhagyshricompany bhagyshricompany self-assigned this Feb 5, 2024
@bhagyshricompany
Copy link

thanks for reporting please share the repro steps.

@bhagyshricompany
Copy link

have you properly used local setting.json file like azurewebjob storage etc.

@icanfathom
Copy link
Author

Yep, local.settings.json is properly configured. I used the wizard to walk through the process.

Reproduction steps (in VS Code):

  1. Ctrl + Shift + P > Azure Functions: Create Function...
  2. Azure Cosmos DB trigger
  3. Provide name
  4. Create new local app settings
  5. Enter DB name
  6. Enter container name
  7. Automatically create lease collection if not exists (true)

The Azure Functions extension does the rest. I did check both my local.settings.json file and my configuration params, and it all seems correct.

@icanfathom
Copy link
Author

@bhagyshricompany See comment above.

@sebpelletier
Copy link

I'm facing the same issue. Creating a brand new Azure Function CosmosDB trigger via the VS Code extension generates this error on function start.

@LuloDev
Copy link

LuloDev commented Mar 5, 2024

Same issue, via VS Code

@mattonecz
Copy link

mattonecz commented Mar 7, 2024

it seems that you need to add 'connection' and 'containerName' instead of connectionStringSetting and collectionName, if you dont the Options probably get recognized as v3Options instead of v4options.

@nagaozen
Copy link

nagaozen commented Mar 8, 2024

it seems that you need to add 'connection' and 'containerName' instead of connectionStringSetting and collectionName, if you dont the Options probably get recognized as v3Options instead of v4options.

@mattonecz is right, VSCode template is just using the wrong key names. For working V4 names, check Configuration

@icanfathom
Copy link
Author

Nice. This got me past my error.

I guess the request here then is to update the VS Code template.

It would also be nice if the Model version was more obvious somehow. Just looking through my config, I'm not sure how I'd know that I should be using Model v4 over v3.

@wreyford
Copy link

This issue still persists with the latest Azure Functions Core Tools updated in VisualStudio Code Insiders, and following all the default prompts to create an Azure Cosmos DB Trigger function. using JavaScript, Model V4.
The template still creates with Incorrect CosmosDBv3TriggerOptions, and not the correct CosmosDBv4TriggerOptions
Thus I need to Edit
connectionStringSetting:
collectionName:
createLeaseCollectionIfNotExists:
to the V4 names:
connection:
containerName:
createLeaseContainerIfNotExists:

This has fortunately been pointed out above, and saved me lots of time.
This is so unfortunate, as otherwise fantastic to use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants