[CSHARP-1669] Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.GuidSerializer' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[System.Nullable`1[System.Guid]]'. Created: 12/May/16 Updated: 05/Apr/19 Resolved: 17/May/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | BSON |
| Affects Version/s: | 2.2.3 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Chad Kreimendahl | Assignee: | Unassigned |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
When attempting to map to a guid within an Elem match, we are getting the above exception. Example code:
|
| Comments |
| Comment by Chad Kreimendahl [ 17/May/16 ] | ||
|
We've added logic around it to make it the equiv of checking for null or not, so that workaround is good enough for us. | ||
| Comment by Craig Wilson [ 16/May/16 ] | ||
|
Hi Chad, The issue is that you are using a nullable guid where the property type is an actual guid. While we could probably have the GuidSerializer implement IBsonSerializer<Nullable<Guid>> as well, we currently don't. The "workaround" is actually quite simple. Change the line from
to
Craig | ||
| Comment by Chad Kreimendahl [ 12/May/16 ] | ||
|
Exception path: System.InvalidCastException: Unable to cast object of type 'MongoDB.Bson.Serialization.Serializers.GuidSerializer' to type 'MongoDB.Bson.Serialization.IBsonSerializer`1[System.Nullable`1[System.Guid]]'. |