Azure Cosmos DB .NET SDK v4: MissingMethodException



我在。net 5的Azure Function App中运行Azure Cosmos DB . net SDK v4 (Azure Cosmos 4.0.0-preview3)。

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

上面的代码抛出错误:

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)'.

如何解决这个问题?

使用AccountEndpoint、Account Key或Resource令牌创建Cosmos客户端时,应配置所需的区域

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

CosmosClient是通过builder模式使用。

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

试试上面的代码。

这个github代码,微软文档帮助我使用cosmos db在azure上部署。net控制台应用程序,没有错误。

有关使用azure cosmos DB . net SDK时的故障排除等更多信息,请查看此