[CSHARP-1423] System.ArgumentException in BsonMemberMap.SetSerializer when trying to apply $select Created: 24/Sep/15 Updated: 08/Dec/21 Resolved: 26/Nov/20 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq, Serialization |
| Affects Version/s: | 2.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Joe Wang | Assignee: | James Kovacs |
| Resolution: | Duplicate | Votes: | 9 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||
| Description |
|
Using the ASP.NET WebApi 2 implementation of OData 3, I'm trying to apply the $select query option to the new IQueryable being returned from the new 2.1 RC driver. I keep running into this error when enumerating the IQueryable, however: System.ArgumentException: Value type of serializer is System.Web.Http.OData.Query.Expressions.PropertyContainer+NamedProperty`1[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] and does not match member type System.Web.Http.OData.Query.Expressions.PropertyContainer. Parameter name: serializer The IQueryable debug view shows this: DebugView ".Call System.Linq.Queryable.Select( .Lambda #Lambda1<System.Func`2[MyObject,System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[MyObject]]>(MyObject $var1) } So it seems like the value of Container (in System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome) is actually not PropertyContainer (which is what's defined in the class), but a SubClass of it, hence causing the exception to be thrown. Might there be a way to resolve this issue in SetSerializer? |
| Comments |
| Comment by James Kovacs [ 26/Nov/20 ] | ||||||||||||||||||||||||||||||||||
|
We have investigated this further and concluded that this issue is a duplicate of
And the following ODataController method:
Querying using the $select OData operator (https://example.com:8888/odata/Products?$select=Name) results in the MongoDB LINQ provider receiving the following expression tree:
Our current LINQ provider does not support LINQ's IIF method, which is why $select (and $expand) in OData fails. We are currently working on a new implementation of our LINQ provider and will make sure IIF works properly in the new implementation. This should allow $select and $expand to work correctly. Since the root cause of this issue and | ||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 20/Nov/20 ] | ||||||||||||||||||||||||||||||||||
|
Sorry for the radio silence on this. We hear you. We're going to re-triage this issue and see if we can come up with a solution. Meanwhile if anyone has any ideas on how to fix it, please share them. | ||||||||||||||||||||||||||||||||||
| Comment by Dimitri Kroo [ 20/Nov/20 ] | ||||||||||||||||||||||||||||||||||
|
Still any plans to fix it? | ||||||||||||||||||||||||||||||||||
| Comment by Diego Dalben [ 12/Jun/20 ] | ||||||||||||||||||||||||||||||||||
|
In June 2020 this error still occurs. Is there a correction forecast? | ||||||||||||||||||||||||||||||||||
| Comment by Yan Wenwei [ 01/Mar/20 ] | ||||||||||||||||||||||||||||||||||
|
It's the year 2020, I am using oData 7.3.0 and MongoDb.Driver 2.10.0. And this issue still exists. Do you have any plans? | ||||||||||||||||||||||||||||||||||
| Comment by Martin Opdenacker [ 15/Nov/19 ] | ||||||||||||||||||||||||||||||||||
|
When can we expect this issue to be resolved ? We really need this. | ||||||||||||||||||||||||||||||||||
| Comment by Joseph Washington [ 21/Nov/18 ] | ||||||||||||||||||||||||||||||||||
|
select and expand do not work for me - Microsoft.AspNetCore.OData 7.1.0, MongoDB.Driver 2.7.2 - Has anyone found a work around? | ||||||||||||||||||||||||||||||||||
| Comment by Ross Buggins [ 29/Oct/18 ] | ||||||||||||||||||||||||||||||||||
|
I can confirm that all the other operations still seem to work (filter, order etc) just select that wont. Ross | ||||||||||||||||||||||||||||||||||
| Comment by Ross Buggins [ 29/Oct/18 ] | ||||||||||||||||||||||||||||||||||
|
Still an issue in latest .net and latest mongodb driver - any thoughts on this one at all? Ross | ||||||||||||||||||||||||||||||||||
| Comment by Christopher Florencia [ 20/Apr/18 ] | ||||||||||||||||||||||||||||||||||
|
The issue is still present with Driver v2.5.1 and Microsoft.AspNetCore.Odata 7.0.0.beta2 (internally Micorosft.Odata.Core 7.3.1) Christopher. | ||||||||||||||||||||||||||||||||||
| Comment by Steve Craze [ 25/Jan/18 ] | ||||||||||||||||||||||||||||||||||
|
Hi, | ||||||||||||||||||||||||||||||||||
| Comment by Semyon Ivanov [ 27/Sep/16 ] | ||||||||||||||||||||||||||||||||||
|
The issue is still present with Driver v2.3.0 and OData v4 (6.0.0) | ||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 05/Feb/16 ] | ||||||||||||||||||||||||||||||||||
|
Hi Johan, I'm not completely positive this is our issue. OData does some very interesting things with an expression tree which require us to handle special OData specific types. We don't have any current plans to handle this. I'll bring it up in our next planning meeting. Craig | ||||||||||||||||||||||||||||||||||
| Comment by Johan Hammar [ 05/Feb/16 ] | ||||||||||||||||||||||||||||||||||
|
As of the current version 2.2.2.10 this issue remains. Until this has been fixed MongoDB cannot be used as a backend to Azure Mobile service (or Mobile App) clients that uses offline sync since it relies on OData queries on the server side. Is there any update on when this will be fixed? | ||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
Ok. Thanks for the report. I don't think this is going to get fixed for 2.1. This is going to be much more involved than I thought. I put a fix for 2.2, but might get it into a 2.1 point release. | ||||||||||||||||||||||||||||||||||
| Comment by Joe Wang [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
Yep--it only happens for $select – all the other OData operators seem to work fine! | ||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
Yeah... Somehow, these are going to have to get translated into an actual POCO object before getting passed to our LINQ provider. We don't know anything about these special types. This only happens for $select? Does OData get translated ok for $filter, $skip, etc...? | ||||||||||||||||||||||||||||||||||
| Comment by Joe Wang [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
The OData project I have is fairly simple – here's an example of what I'm doing:
in the controller:
From digging around the OData code, the Select expression (say for selecting MyObject.Name) it appears to build is as follows:
where
(I've abbreviated the classes here, full source at https://github.com/OData/WebApi/tree/master/OData/src/System.Web.Http.OData/OData/Query/Expressions) | ||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
The SelectBinder supports a lot of things, all related to either a POCO or a BsonDocument. What the above looks like is something else which needs special interpretation. I haven't done any work on integrating with OData yet. It might be that we need to do some special mapping for OData to work correctly given that it's generating naming containers and what not... Would you mind posting a sample OData project so I can see how you are using OData. | ||||||||||||||||||||||||||||||||||
| Comment by Joe Wang [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
Also, it seems like the Select Expression being generated is something along the lines of MongoQueryable.Select(var => new { Name = "id", Value = var.id, Next = new { Name = "Name", Value = var.Name, Next = new {...}} }) which the current SelectBinder doesn't support. | ||||||||||||||||||||||||||||||||||
| Comment by Joe Wang [ 25/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
Just to see what would happen, I took a local build and commented out the check in SetSerializer – it goes further, but throws requiring that the LambdaExpression.Name be populated – and it seems like the behavior of the OData library currently does not do this | ||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 24/Sep/15 ] | ||||||||||||||||||||||||||||||||||
|
No, I don't think this is something to do in SetSerializer. But I may be able to do something in LINQ. I'll take a look. Thanks for reporting. |