-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.1
-
Component/s: Linq, Serialization
-
None
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
at MongoDB.Bson.Serialization.BsonMemberMap.SetSerializer(IBsonSerializer serializer)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildClassMap(Type type, ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildProjectedSerializer(ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildMemberInit(MemberInitExpression node)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.Build(Expression node)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildClassMap(Type type, ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildClassMap(Type type, ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildClassMap(Type type, ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildProjectedSerializer(ProjectionMapping mapping)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.BuildMemberInit(MemberInitExpression node)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.Build(Expression node)
at MongoDB.Driver.Linq.Processors.SerializerBuilder.Build(Expression node, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.Processors.PipelineBindingContext.GetSerializer(Type type, Expression node)
at MongoDB.Driver.Linq.Processors.Pipeline.MethodCallBinders.SelectBinder.Bind(PipelineExpression pipeline, PipelineBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
at MongoDB.Driver.Linq.Processors.MethodInfoMethodCallBinder`1.Bind(PipelineExpression pipeline, TBindingContext bindingContext, MethodCallExpression node, IEnumerable`1 arguments)
at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.BindMethodCall(MethodCallExpression node)
at MongoDB.Driver.Linq.Processors.PipelineBinderBase`1.Bind(Expression node)
at MongoDB.Driver.Linq.Processors.Pipeline.PipelineBinder.Bind(Expression node, IBsonSerializer rootSerializer, IBsonSerializerRegistry serializerRegistry)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Prepare(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Translate(Expression expression)
at MongoDB.Driver.Linq.MongoQueryProviderImpl`1.Execute(Expression expression)
at MongoDB.Driver.Linq.MongoQueryableImpl`2.GetEnumerator()
at MongoDB.Driver.Linq.MongoQueryableImpl`2.System.Collections.IEnumerable.GetEnumerator()
at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteFeed(IEnumerable enumerable, IEdmTypeReference feedType, ODataWriter writer, ODataSerializerContext writeContext)
at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObjectInline(Object graph, IEdmTypeReference expectedType, ODataWriter writer, ODataSerializerContext writeContext)
at System.Web.Http.OData.Formatter.Serialization.ODataFeedSerializer.WriteObject(Object graph, Type type, ODataMessageWriter messageWriter, ODataSerializerContext writeContext)
at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, HttpContent content, HttpContentHeaders contentHeaders)
at System.Web.Http.OData.Formatter.ODataMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)
The IQueryable debug view shows this:
DebugView ".Call System.Linq.Queryable.Select(
.Constant<MongoDB.Driver.Linq.IMongoQueryable`1[MyObject]>(aggregate([])),
'(.Lambda #Lambda1<System.Func`2[MyObject,System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[MyObject]]>))
.Lambda #Lambda1<System.Func`2[MyObject,System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[MyObject]]>(MyObject $var1)
{
.New System.Web.Http.OData.Query.Expressions.SelectExpandBinder+SelectSome`1[MyObject](){
ModelID = \"b5ae8d92-3fb0-4049-a9f2-c72805d87209\",
Container = .New System.Web.Http.OData.Query.Expressions.PropertyContainer+AutoSelectedNamedPropertyWithNext`1[System.String]()
{
Name = \"id\",
Value = $var1.id,
Next = .New System.Web.Http.OData.Query.Expressions.PropertyContainer+NamedProperty`1[System.String]()
}
}
}" string
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?
- duplicates
-
CSHARP-1771 Support IIF method (i.e. ternary operator) in LINQ
- Closed
- is depended on by
-
CSHARP-3989 oDATA $select support with LINQ3
- Closed