question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CosmosDB 4.0.0-preview1 always throws an exception when AAD authentication is configured

See original GitHub issue

Whenever I set up and run CosmosDBTrigger or CosmosDB to use AAD authentication, it throws a NullReferenceException and fails to start.

I checked and found that AzureComponentFactory is always passed null for DefaultCosmosDBServiceFactory. The root cause seems to be that AddAzureClientsCore is not registered in the DI.

Example (Service Bus Extension) : https://github.com/Azure/azure-sdk-for-net/blob/4162f6fa2445b2127468b9cfd080f01c9da88eba/sdk/servicebus/Microsoft.Azure.WebJobs.Extensions.ServiceBus/src/Config/ServiceBusHostBuilderExtensions.cs#L91-L93

Repro steps

  1. Create new function (v3) project
  2. Add CosmosDBTrigger function
  3. Update Microsoft.Azure.WebJobs.Extensions.CosmosDB version 4.0.0-preview1
  4. Setup RBAC and connection string
  5. Run function app

Expected behavior

An error always occurs when starting Function.

[2021-09-01T15:07:18.499Z] Microsoft.Azure.WebJobs.Host: Error indexing method 'Function2'. 
Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create container information for TodoItem in database SampleDB with lease leases in database SampleDB : Object reference not set to an instance of an object. 
Microsoft.Azure.WebJobs.Extensions.CosmosDB: Object reference not set to an instance of an object.
[2021-09-01T15:07:18.536Z] Error indexing method 'Function2'

Actual behavior

CosmosDBTrigger and Managed Identity can be used without any errors.

Known workarounds

  • Install Microsoft.Azure.WebJobs.Extensions.Storage (At the same time, AddAzureClientsCore is added to the DI, so)

Related information

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ealsurcommented, Sep 10, 2021

Should be fixed in preview2 release

2reactions
ealsurcommented, Sep 1, 2021

@shibayan sent a PR with the fix, thanks for reporting

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot Azure Cosmos DB forbidden exceptions
If the request came to Azure Cosmos DB via the expected path, request was blocked because the source network identity was not configured...
Read more >
Azure Cosmos DB extension for Azure Functions update with ...
... Azure Cosmos DB extension for Azure Functions uses the latest Azure Cosmos DB .NET SDK to add support for Azure AD authentication....
Read more >
Spring Cloud Azure - Reference Documentation
Starter for using Azure Cosmos DB and Spring Data Cosmos DB ... To configure how to authenticate with Azure Active Directory for one...
Read more >
Azure Cosmos DB (SQL API)
Azure Active Directory (Azure AD) authentication. The Azure Cosmos DB state store component supports authentication using all Azure Active Directory mechanisms.
Read more >
Azure Cosmos DB client throws "HttpRequestException
HttpRequestException : An attempt was made to access a socket in a way forbidden by its access permissions. I use following configuration:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found