[CSHARP-4793] Unable to cast object of type 'MongoDB.Bson.BsonNull' to type 'MongoDB.Bson.BsonDocument Created: 18/Sep/23  Updated: 20/Sep/23  Resolved: 20/Sep/23

Status: Closed
Project: C# Driver
Component/s: Change Streams
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Raymond Chan Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Case:
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

Account/Company Name: Synergy Sports Technology LLC

Issue + Relevant Info

Customer is getting the following error message in their C# code after upgrading to version 7.0. They are running changeStream and their code requires pre- and post-images (have [changeStreamPreAndPostImages.enabled: true] set)

System.InvalidCastException: Unable to cast object of type 'MongoDB.Bson.BsonNull' to type 'MongoDB.Bson.BsonDocument'.
at MongoDB.Bson.BsonValue.get_AsBsonDocument()
at MongoDB.Driver.ChangeStreamDocument`1.get_FullDocumentBeforeChange()

They are running C# version 2.20.0 and is compatible with 7.0
https://www.mongodb.com/docs/drivers/csharp/current/compatibility/#std-label-csharp-compatibility-tables

Found this Jira that might be related - CSHARP-4745

Portion of customer's code snippets they use for changeStreams:

await database.WatchAsync(pipeline, new ChangeStreamOptions
{
ResumeAfter = token.Token,
FullDocument = ChangeStreamFullDocumentOption.WhenAvailable,
FullDocumentBeforeChange = ChangeStreamFullDocumentBeforeChangeOption.WhenAvailable
}, cancellationToken);

this gets full document from ChangeStreamDocument<BsonDocument> change like this:
var fullDocument = change.FullDocument != default ? change.FullDocument : change.FullDocumentBeforeChange; - this line throws an exception

Requested Action

  • Investigate and advise what may be the cause and workaround
  • Verify if this is may be related to CSHARP-4745

Status

Customer Name Synergy Sports Technology LLC
Is the customer production-down NOW? *NO*
Intercom/Case Link and Severity NA
Link to Cluster Org/Project/Cluster Link - (M20 Instance)
Affected Nodes & Status
Have I attempted to restart the affected nodes? *NO*


 Comments   
Comment by Raymond Chan [ 20/Sep/23 ]

recreated this request in HELP-50259  to set to the correct project type

closing this ticket

Comment by Raymond Chan [ 19/Sep/23 ]

Customer observed that the errors seems to be related to  ChangeStreamDocument.OperationType == Delete

Generated at Wed Feb 07 21:49:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.