[CSHARP-445] MongoCursor .ToList() throws System.NullReferenceException if .SetFields has been called Created: 15/Apr/12  Updated: 20/Mar/14  Resolved: 18/Apr/12

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

Type: Bug Priority: Major - P3
Reporter: Paul Brower Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

var results_Works =
MongoDatabase.Create("someconnstring").GetCollection<Swine>("Swine").Find(Query.EQ("AnimalId", "123456")).ToList();

var results_DoesntWork =
MongoDatabase.Create("someconnstring").GetCollection<Swine>("Swine").Find(Query.EQ("AnimalId", "123456")).SetFields("AnimalId").ToList();



 Comments   
Comment by Robert Stam [ 15/Apr/12 ]

No problem. I was just trying to reproduce it and couldn't, but no harm done. Thanks for the update.

I am surprised you had to put [BsonIgnore] on a read-only property. Read-only properties are supposed to be ignored automatically. If you can provide a simple class definition and sample code that results in a NullReferenceException I would like to look at that.

Comment by Paul Brower [ 15/Apr/12 ]

Shoot, twice in the last few days ... I will try to do a better job validating my issues are actually bugs before I create them here.

You can close this ... it's not a bug with the driver. I had a readonly property that should have had a [BsonIgnore] attribute on it. All is working well now.

I apologize for any time you wasted on this.

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