[CSHARP-313] When calling ToBsonDocument() on an extension method, throw a more useful exception Created: 05/Sep/11  Updated: 02/Apr/15  Resolved: 30/Sep/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.1
Fix Version/s: 1.3

Type: Improvement Priority: Minor - P4
Reporter: Justin Dearing Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: exception
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All



 Description   

The line Console.WriteLine("A String".ToBsonDocument()); throws InvalidOperationException WriteString can only be called when State is Value, not when State is Initial. A more useful exception should be thrown higher up.



 Comments   
Comment by Robert Stam [ 30/Sep/11 ]

Looked at the pull request but decided that it would be better to put the error checking at a lower level. That way ToBson gets the new error message as well, as does a direct call to BsonSerializer.Serialize. Thanks for your help. It pointed in the right direction.

Comment by Robert Stam [ 28/Sep/11 ]

Probably. Haven't had a chance to look at them yet. But that's why I changed the fix version to 1.3, to put this on the todo list.

Comment by Justin Dearing [ 28/Sep/11 ]

Robert,

Are you going to merge my changes? https://github.com/zippy1981/mongo-csharp-driver/commits/csharp-313

Justin

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