[CSHARP-3149] Error in Auto class map with constructor parameter mismatch Created: 02/Jul/20 Updated: 27/Oct/23 Resolved: 13/Jul/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Serialization |
| Affects Version/s: | 2.10.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Gian Maria Ricci | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Description |
|
If you create a C# class with a property of type array and the constructor accepts an IEnumerable for that parameter the driver is not able to map the class. Attached program that raises the exception. But basically here is the problem, this class triggers the error public class TestArray public String Id { get; private set; } public String[] Values { get; private set; } This happens because the constructor accepts a parameter vlaues THAT HAS THE SAME NAME OF A PROPERTY BUT DIFFERENT TYPE, this generates the exception. Also the error is not present if properties setters are public (because the mapper directly map properties). Actually this is a serious bug, I've updated driver on a project of mine and I have tons of test failing for such classes. Everything was fine with 2.7 driver. |
| Comments |
| Comment by Esha Bhargava [ 13/Jul/20 ] |
|
alkampfer Thanks! Closing this as works as designed. |
| Comment by Gian Maria Ricci [ 03/Jul/20 ] |
|
Yes, I've already fixed my code. I think that the bug can be closed with a not in Release Notes as breaking changes for the driver.
Actually moving from 2.7 to 2.10 should be a no brainer because I did not find any breaking changes in release notes, but I think this is a breaking changes that should be somewhat documented.
Thanks. |
| Comment by Dmitry Lukyanov (Inactive) [ 02/Jul/20 ] |
|
Hello alkampfer Thanks for your report, try to use the same type for Values property and value ctor argument (either string[] or Ienumerable<string> in both cases). Currently, we recognize this case as an immutable class that has a bit different processing. See this comment for details: https://jira.mongodb.org/browse/CSHARP-2889?focusedCommentId=3212482&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-3212482 |