azure - 将默认 CosmosSerializationOptions 更改为驼峰命名法会导致 CosmosDB SDK V4 中出现异常

标签 azure azure-cosmosdb azure-cosmosdb-sqlapi

我在使用 CosmosDB SDK V4.0.0-preview3 时遇到问题。当我尝试更改默认的 CosmosSerializationOptions 时,当我尝试使用 GetItemQueryIterator 时,它会导致异常。除了这个方法之外,其他一切都工作正常。

var client = new CosmosClientBuilder(connectionString)
    .WithSerializerOptions(new CosmosSerializationOptions { PropertyNamingPolicy = CosmosPropertyNamingPolicy.CamelCase })
    .Build();
var container = client.GetContainer("SocialNetwork", "Posts"); 
var query = new QueryDefinition("SELECT * FROM c");
await foreach (var item in container.GetItemQueryIterator<Post>(query))
{
    Console.WriteLine(item);
}

异常消息:

Unhandled exception. System.ArgumentNullException: Value cannot be null. (Parameter 'source')
   at System.Linq.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Azure.Cosmos.CosmosResponseFactory.CreateQueryFeedResponseWithSerializer[T](Response cosmosResponseMessage, CosmosSerializer serializer)
   at Azure.Cosmos.CosmosResponseFactory.CreateQueryFeedResponse[T](Response cosmosResponseMessage)
   at Azure.Cosmos.PageIteratorCore`1.GetPageAsync(String continuation, CancellationToken cancellationToken)
   at Azure.Cosmos.PageResponseEnumerator.FuncAsyncPageable`1.AsPages(String continuationToken, Nullable`1 pageSizeHint)+MoveNext()
   at Azure.Cosmos.PageResponseEnumerator.FuncAsyncPageable`1.AsPages(String continuationToken, Nullable`1 pageSizeHint)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at Azure.AsyncPageable`1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext()
   at Azure.AsyncPageable`1.GetAsyncEnumerator(CancellationToken cancellationToken)+MoveNext()
   at Azure.AsyncPageable`1.GetAsyncEnumerator(CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()
   at ConsoleAppCosmosDb.Program.Main(String[] args) in C:\Users\XPS\source\repos\ConsoleAppCosmosDb\ConsoleAppCosmosDb\Program.cs:line 29
   at ConsoleAppCosmosDb.Program.Main(String[] args) in C:\Users\XPS\source\repos\ConsoleAppCosmosDb\ConsoleAppCosmosDb\Program.cs:line 29
   at ConsoleAppCosmosDb.Program.<Main>(String[] args)

如果我删除此选项或将 CamelCase 更改为 Default 一切正常。

最佳答案

https://github.com/Azure/azure-cosmos-dotnet-v3/issues/1193 中所述,这似乎是预览版 V4 版本上的一个错误。

主要与V4预览状态有关,部分内部连线待移植。

您目前可以通过在 Post 类上使用 JsonPropertyName 并在其中使用 Camel Case 来解决此问题。

关于azure - 将默认 CosmosSerializationOptions 更改为驼峰命名法会导致 CosmosDB SDK V4 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60014907/

相关文章:

Azure 资源管理器 - Microsoft.Storage/storageAccounts 与 microsoft.classic storage/storageAccounts

azure - 如何调用azure web作业并传递参数

azure - JHipster 使用 Azure Active Directory 而不是 Keycloak 或 Okta

azure-cosmosdb - Gremlin groupCount() 仅返回 gt 2

C# Cosmos DB 补丁 - 将元素插入子集合

database - CosmosDB 中 GROUP BY 的索引

azure - 设置 IpRangeFilter 时 Microsoft.Azure.Management.CosmosDB.Fluent 失败

node.js - 无法执行存储过程: 'One of the specified inputs is invalid.'

azure - 如何备份 Azure Cosmos DB

c# - 如何在同一查询中使用 DISTINCT 和 VALUE?