Azure Cosmos DB .NET SDK v4: MissingMethodException

Viewed 299

I am running Azure Cosmos DB .NET SDK v4 (Azure Cosmos 4.0.0-preview3) in Azure Function App in .NET5.

         CosmosClient cosmosClient = new CosmosClientBuilder(account, key)
                .Build();

Above code throws error:

An exception of type 'System.MissingMethodException' occurred in Azure.Cosmos.dll but was not handled in user code
Method not found: 'System.String Microsoft.Azure.Documents.IAuthorizationTokenProvider.GetUserAuthorizationToken(System.String, System.String, System.String, Microsoft.Azure.Documents.Collections.INameValueCollection, Microsoft.Azure.Documents.AuthorizationTokenType, System.String ByRef)'.

How can I resolve this?

1 Answers

When creating the Cosmos client with AccountEndpoint, Account Key or Resource token and should be configure with required region.

CosmosClient cosmosClient = new CosmosClient(
"account-endpoint-from-portal",
 "account-key-from-portal",
 new CosmosClientOptions()
 {      ApplicationRegion = Regions.EastUS2     });

The CosmosClient is created through builder pattern using .

CosmosClient cosmosClient = new CosmosClientBuilder("connection-string-from-portal")
.WithApplicationRegion("East US 2")
.Build();

Try with the above code.

This github code, Microsoft documentation helped me to deploy .net console application on azure using cosmos db without error.

For more information like troubleshooting issues when using azure cosmos DB .NET SDK, check this.

Related