InvalidOperationException: ReadName can only be called when State is Name, not when State is EndOfDocument

huangapple go评论70阅读模式
英文:

InvalidOperationException: ReadName can only be called when State is Name, not when State is EndOfDocument

问题

我在使用MongoDB.Driver版本"2.19.0"时遇到了这个异常。代码如下(其中Configuration是一个子文档):

return await _customerCollection.Find(x => x.CustomerId == id).Project(x => x.Configuration).FirstOrDefaultAsync();

在版本2.18上它只返回null。这是否是Mongo C#驱动程序的一个bug?

英文:

I get that exception when using MongoDB.Driver Version="2.19.0". The code is (Configuration being a subdocument):

return await _customerCollection.Find(x => x.CustomerId == id).Project(x => x.Configuration).FirstOrDefaultAsync();

On Version 2.18 it just returns null. Is this a bug in the Mongo C# driver?

答案1

得分: 1

这个问题我也遇到过,看起来在2.19.2版本中已修复。

英文:

I had the same issue, this appears to be fixed in 2.19.2

答案2

得分: 0

异常仅对没有 Configuration 的客户文档抛出。但由于在 2.18 版本中没有发生这种情况,我认为这是在 2.19 中引入的 MongoDB.Driver 错误。

目前,我已将代码更改为:

var customer = await _customerCollection.Find(x => x.CustomerId == id).FirstOrDefaultAsync();
return customer?.Configuration;
英文:

The exception is thrown only for Customer documents that don't have a Configuration. Still, since it didn't happen in 2.18 I suppose this is a MongoDB.Driver bug introduced in 2.19.

At the moment I changed the code to:

var customer = await _customerCollection.Find(x => x.CustomerId == id).FirstOrDefaultAsync(); 
return customer?.Configuration;

huangapple
  • 本文由 发表于 2023年3月15日 20:34:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/75744763.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定