C# Client fails to deserialize response from action bound to a contained entity · Issue #946 · OData/AspNetCoreOData · GitHub
More Web Proxy on the site http://driver.im/
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My controller looks like this and works returns a new instance:
publicclassDataItemsController:ODataController{protectedBackendDataContextContext{get;}=newBackendDataContext();[EnableQuery(PageSize=512,EnsureStableOrdering=false)]publicIQueryable<DataItem>Get(){returnContext.DataItems;}[EnableQuery(PageSize=512,EnsureStableOrdering=false)]publicSingleResult<DataItem>Get([FromODataUri]intkey){returnSingleResult.Create(Context.DataItems.Where(e =>e.Id==key));}[HttpPost]publicIHttpActionResultTestAction([FromODataUri]intkey,ODataActionParametersparameters){returnCreated(newNestedItem($"Test for {key}"));}}
System.FormatException: Input string was not in a correct format.atSystem.Number.StringToNumber(Stringstr,NumberStylesoptions,NumberBuffer&number,NumberFormatInfoinfo,BooleanparseDecimal)
This exception is thrown when the method KeysAsSegmentsLiteralParser.TryParseLiteral is called with the value "NestedItem" instead of a key.
The next exception then is this:
Microsoft.OData.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.InvalidOperationException: The response payload is a not a valid response payload. Please make sure that the top level element is a valid Atom or JSON element or belongs to 'http://docs.oasis-open.org/odata/ns/data' namespace.
at Microsoft.OData.Client.Materialization.ODataMaterializer.CreateODataMessageReader(IODataResponseMessage responseMessage, ResponseInfo responseInfo, ODataPayloadKind& payloadKind)
at Microsoft.OData.Client.Materialization.ODataMaterializer.CreateMaterializerForMessage(IODataResponseMessage responseMessage, ResponseInfo responseInfo, Type materializerType, QueryComponents queryComponents, ProjectionPlan plan, ODataPayloadKind payloadKind, MaterializerCache materializerCache)
at Microsoft.OData.Client.MaterializeAtom..ctor(ResponseInfo responseInfo, QueryComponents queryComponents, ProjectionPlan plan, IODataResponseMessage responseMessage, ODataPayloadKind payloadKind, MaterializerCache materializerCache)
at Microsoft.OData.Client.QueryResult.CreateMaterializer(ProjectionPlan plan, ODataPayloadKind payloadKind)
at Microsoft.OData.Client.QueryResult.ProcessResult[TElement](ProjectionPlan plan)
at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
--- End of inner exception stack trace ---
at Microsoft.OData.Client.DataServiceRequest.Execute[TElement](DataServiceContext context, QueryComponents queryComponents)
at Microsoft.OData.Client.DataServiceContext.InnerSynchExecute[TElement](Uri requestUri, String httpMethod, Nullable`1 singleResult, OperationParameter[] operationParameters)
at Microsoft.OData.Client.DataServiceContext.Execute[TElement](Uri requestUri, String httpMethod, Boolean singleResult, OperationParameter[] operationParameters)
at Microsoft.OData.Client.DataServiceActionQuerySingle`1.GetValue()
at Frontend.Program.Main() in C:\Users\hkrause\Downloads\SampleApplication\Frontend\Program.cs:line 14
Microsoft.OData.Client 7.16.0
Reproduce steps
The sample application linked obove contains a full repo.
Expected result
The client can deserialize the response from the server
Actual result
The exception mentioned above is thrown.
Additional detail
None
The text was updated successfully, but these errors were encountered:
This appears to be a bug. We should be able to determine the appropriate context URL since we have information about the parent in the request URL. We seem to be generating the location URL correctly.
I have an application that has an entity set ("DataItem") which in turn contains a contained entityset ("NestedItem") (See SampleApplication.zip).
There is also an action bound to a specific DataItem which creates an instance of NestedItem.
My data model looks like this:
This is my EDM model:
My controller looks like this and works returns a new instance:
When I call the test action with this request:
I get this response:
And the culprit, I think, is that the context is incorrect.
It is:
But shouldn't it be this?
The client app is complaining:
This exception is thrown when the method
KeysAsSegmentsLiteralParser.TryParseLiteral
is called with the value "NestedItem" instead of a key.The next exception then is this:
Microsoft.OData.Client 7.16.0
Reproduce steps
The sample application linked obove contains a full repo.
Expected result
The client can deserialize the response from the server
Actual result
The exception mentioned above is thrown.
Additional detail
None
The text was updated successfully, but these errors were encountered: