[CSHARP-3818] Bool? on .Net Core 2.1 it is not being bound on .Net Core 3.1 - Unable to cast object of type 'MongoDB.Bson.BsonBoolean' to type 'MongoDB.Bson.BsonArray'. Created: 26/Aug/21 Updated: 27/Oct/23 Resolved: 28/Aug/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | 2.13.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Unknown |
| Reporter: | Patrick Ferraro | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | triage | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
macOS Catalina 10.15.7, Mongo Atlas 4.4.8 |
||
| Issue Links: |
|
||||||||
| Description |
|
I had a project in .Net Core 2.1 that was working fine. One of my classes has a prop like: public bool? Terms { get; set; } Was working fine. After I upgraded to .Net Core 3.1, the old items of the collection started to throw errors when biding to this prop. The wierd part is that the new regs created from 3.1, dont throw any error on the bind of this prop. The 2.1 reg and the the 3.1 has the same value on MongoDB: "Terms" : null For the old ones, the error thrown is: Unable to cast object of type 'MongoDB.Bson.BsonBoolean' to type 'MongoDB.Bson.BsonArray'. |
| Comments |
| Comment by Boris Dogadov [ 27/Aug/21 ] |
|
Thanks for the update patrick@boutique-pool.com, closing this ticket then. |
| Comment by Patrick Ferraro [ 27/Aug/21 ] |
|
Hi Boris, I think it would be better to close this item I´ve opened. I'm sorry, I thought the problem would be the driver, but it's not. The driver brings the correct information normally, what is causing the problem is when the API project tries to render the object to the controller's response. I see it's a serialization issue related to System.Text.Json which is the default library of .Net Core 3.1. I switched to the old NewtonSoft and it worked perfectly. Not being a Mongo problem or a driver, do you think it's necessary for me to send the project that can show this problem? |
| Comment by Boris Dogadov [ 26/Aug/21 ] |
|
Hi patrick@boutique-pool.com Could you please provide a simple app reproducing this bug, and a full stack trace? |