[CSHARP-1751] Generic Collection throws "{document} is not supported." on ReplaceOneAsync Created: 20/Aug/16 Updated: 22/Aug/16 Resolved: 22/Aug/16 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | API, Operations |
| Affects Version/s: | 2.2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Tseng [X] | Assignee: | Unassigned |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | driver, query | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
OS: Windows 10, MongoDB: 3.2.9 (Windows Server 2008 R2 with SSL) |
||
| Issue Links: |
|
||||||||
| Description |
|
When trying to add a generic class to the collection, MongoDB CSharp Driver throws an System.AggregateException exception.
I am using the following Model for the collection
The idea is to have *one* collection, to hold indexed item for multiple types, i.e. IndexedItem<User> to index the user (i.e. for AutoComplete functionality). Expected result:
|
| Comments |
| Comment by Tseng [X] [ 22/Aug/16 ] | ||||||||||||
|
Sure, can be closed. The workaround should allow me to work past the error. It was blocking me for days already | ||||||||||||
| Comment by Craig Wilson [ 22/Aug/16 ] | ||||||||||||
|
I forgot about that problem. What you are now hitting is an existing bug ( Let me know if it's ok to close this ticket and start discussing options in the other. | ||||||||||||
| Comment by Tseng [X] [ 22/Aug/16 ] | ||||||||||||
|
Thanks, very helpful. This brought me a little further. But the inserted type has (viewed in MongoDB Management Studio)
The "_t" value shows IndexedItem`1 which seems wrong, it only has the name of the generic, but not the generic args in it and it's not full qualified name. I'd expected something like "Project.Models.IndexedItems<Project.Models.Tag>, Project.Contracts" where "Project.Contracts" is the assembly name. How would the deserializes know to which class to cast it back then without the generic args or the full qualified name? | ||||||||||||
| Comment by Craig Wilson [ 22/Aug/16 ] | ||||||||||||
|
I believe it's the code i.GetType() == typeof(IndexedItem<T>) that isn't working. I believe you can change the check to an "is" and it should work.
I'm unclear as to whether you are storing the discriminator manually or letting us do it. If you are letting us do it, you can use the OfType method before ReplaceOneAsync. Something like this:
Craig |