[CSHARP-1549] findOneAndUpdate - C# duplicate key error Created: 29/Jan/16 Updated: 05/Apr/19 Resolved: 02/Feb/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Testing |
| Affects Version/s: | 2.2.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Patrick Sheehan | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | c#, question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Visual Studio 2015 with Mongo C# Client 2.2.2 |
||
| Attachments: |
|
| Description |
|
InnerException: "An item with the same key has already been added"
|
| Comments |
| Comment by Robert Stam [ 02/Feb/16 ] |
|
Thanks for letting us know. |
| Comment by Patrick Sheehan [ 02/Feb/16 ] |
|
The customer has removed the static constructor and now everything works as expected. Thanks for the assistance! You may close this ticket as resolved. |
| Comment by Robert Stam [ 29/Jan/16 ] |
|
Thanks for providing the code to reproduce this. That made it much easier for me to figure out what is happening. Static constructors are not a good place to be calling RegisterClassMap from, because you have no control over when the static constructor is called. In this case by the time your static constructor is called the driver has already automatically registered a class map for the Counter class, so your call to RegisterClassMap results in a duplicate key error. If you need to call RegisterClassMap be sure to do so as early as possible in the startup code of your application to make sure it gets registered before the driver encounters the need to automatically register one. In this particular sample application, you don't even need to call RegisterClassMap at all because the defaults will do the same thing that your call to RegisterClassMap is doing. |