[CSHARP-4535] Client cannot resolve serializer anymore when using IQueryable with base type Created: 18/Feb/23 Updated: 15/Nov/23 |
|
| Status: | Backlog |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Unknown |
| Reporter: | Sebastian Stehle | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 4 |
| Labels: | triage | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
||||||||
| Issue Links: |
|
||||||||
| Description |
|
I have a public class `Entity` and an entity that inherits from that called `MongoEntity`. The MongoEntity is an implementation detail of the repository, so it is used only internally and is not exposed outside. e.g. something like this:
Until 2.18.0 it works fine, but it breaks with 2.19.0: I get the following exception in my sample:
In my real application I get the following error:
I was not able to reproduce this exception in my sample, but I guess it is the same root issue. My very little example is attached. |
| Comments |
| Comment by Cam Murray [ 15/Nov/23 ] | ||
|
Also experiencing this issue which has forced me to downgrade to LINQ2. Hopefully we get this fixed soon, thank you for your support! | ||
| Comment by Sys Ops [ 19/Oct/23 ] | ||
|
P.S. Could you please update the Jira component to "LINQ3" if this only affects LINQ3? | ||
| Comment by Sys Ops [ 12/Oct/23 ] | ||
|
Hi robert@mongodb.com, now in October I had hoped these critical LINQ3 issues would have been fixed by now. But if we run with the latest driver (2.22.0 ) our code still breaks with this error† blocking us from enabling LINQ3 until its fixed. † Also System.ArgumentException: ValueType 'Xxx.Yyy.Data.Questions.Section' of parameterSerializer does not match parameter type 'Xxx.Yyy.Data.CollectionItems.CollectionItem'. (Parameter 'parameterSerializer' | ||
| Comment by Robert Stam [ 30/Mar/23 ] | ||
|
Thanks for catching that. I've created | ||
| Comment by Jean Llorca [ 30/Mar/23 ] | ||
|
I also use this pattern. | ||
| Comment by Sebastian Stehle [ 22/Feb/23 ] | ||
|
Thanks for the workaround | ||
| Comment by Robert Stam [ 22/Feb/23 ] | ||
|
Thanks for the further information. I will continue looking into how to make this type of casting work with the new LINQ3 provider. In the meantime you can manually select to continue using the LINQ2 provider like this:
| ||
| Comment by Sebastian Stehle [ 22/Feb/23 ] | ||
|
The cast from `IMongoQueryable<MongoEntity>` to `IQueryable<MongoEntity>` works fine. And it always works with 2.18.0, so you must have changed something. Typically I do not expose IQueryable but it is necessary for the IUserStore in AspNet Identity. | ||
| Comment by Robert Stam [ 21/Feb/23 ] | ||
|
I am able to reproduce this issue, and it is related to casting the `IMongoQueryable<MongoEntity>` to an `IQueryable<Entity>`. I'm a little surprised changing `MongoEntity` to `Entity` did not result in a compilation error, but I guess that's because of the `out T` in the declaration of `IQueryable<out T>`. This might not be easy to support (in general we weren't expecting users to cast `IMongoQueryable<T>` to `IQueryable<T>`, and certainly weren't expecting the type of `T` to change). I'll investigate futther... | ||
| Comment by Robert Stam [ 21/Feb/23 ] | ||
|
Thank you for reporting this issue. I will begin investigating it soon. |