[CSHARP-2405] ImmutableTypeClassMapConvention should not consider static properties Created: 03/Oct/18 Updated: 28/Oct/23 Resolved: 06/Nov/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.7.0 |
| Fix Version/s: | 2.9.3 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Sergey Rodyushkin | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 2 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Backwards Compatibility: | Fully Compatible |
| Description |
|
Consider the following immutable class:
The ImmutableTypeClassMapConvention refuses to map such a class, because when obtaining the properties of a type, it calls the GetProperties method with no parameters. According to the MSDN documentation, both instance and static properties of a type are returned in this case. The suggested fix is to consider instance properties only by setting the correct BindingFlags.
|
| Comments |
| Comment by Githook User [ 06/Nov/19 ] |
|
Author: {'username': 'rbugginsvia', 'email': '31471952+rbugginsvia@users.noreply.github.com', 'name': 'rbugginsvia'}Message: |
| Comment by Githook User [ 06/Nov/19 ] |
|
Author: {'name': 'rbugginsvia', 'username': 'rbugginsvia', 'email': '31471952+rbugginsvia@users.noreply.github.com'}Message: |
| Comment by Ross Buggins [ 22/Oct/18 ] |
|
I'm using this in F# and i am having the same issue with a type that has static members. As soon as these are removed then this works.
I've edited line 42 to be: var properties = typeInfo.GetProperties(BindingFlags.Instance | BindingFlags.Public ); and this now solves this problem. See PR https://github.com/mongodb/mongo-csharp-driver/pull/350
|