【问题标题】:Changing default CosmosSerializationOptions to camelCase causes an exception in CosmosDB SDK V4将默认 CosmosSerializationOptions 更改为 camelCase 会导致 CosmosDB SDK V4 中的异常
【发布时间】:2020-02-01 07:27:28
【问题描述】:

我的 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 一切正常。

【问题讨论】:

    标签: azure azure-cosmosdb azure-cosmosdb-sqlapi


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2016-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      • 2013-08-07
      • 1970-01-01
      相关资源
      最近更新 更多