Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OData Client 7.6.4 is getting this error "In OData, a top-level error object must have exactly one property with name 'error'" #1756

Closed
ImGonaRot opened this issue Apr 24, 2020 · 3 comments · Fixed by #1764
Assignees
Labels
bug client only related to OData.Client P2 regression

Comments

@ImGonaRot
Copy link

OData Client 7.6.4

When I upgraded the Microsoft.OData.Client from 7.6.3 to 7.6.4 I am receiving the following error when I try to serialize an ODataError object into the Response "Content" and the OData client tries to deserialize the response.

On client 7.6.3 it works fine.

NOTE: I am listing the OData service code that can be used to test the exception from the service.
This is not a server side issue and only occurs when updating the client to 7.6.4

Microsoft.OData.Client.DataServiceQueryException: An error occurred while processing this request. ---> System.InvalidOperationException: An error occurred while processing this request. ---> Microsoft.OData.ODataException: A property with name 'ErrorCode' was found in the error object when reading a top-level error. In OData, a top-level error object must have exactly one property with name 'error'.
at Microsoft.OData.JsonLight.ODataJsonLightErrorDeserializer.ReadTopLevelErrorImplementation () [0x00028] in <3821c67bef1a4240aa87fa2afb20b4a9>:0
at Microsoft.OData.JsonLight.ODataJsonLightErrorDeserializer.ReadTopLevelError () [0x0001e] in <3821c67bef1a4240aa87fa2afb20b4a9>:0
at Microsoft.OData.JsonLight.ODataJsonLightInputContext.ReadError () [0x00007] in <3821c67bef1a4240aa87fa2afb20b4a9>:0
at Microsoft.OData.ODataMessageReader+<>c.b__68_0 (Microsoft.OData.ODataInputContext context) [0x00000] in <3821c67bef1a4240aa87fa2afb20b4a9>:0
at Microsoft.OData.ODataMessageReader.ReadFromInput[T] (System.Func2[T,TResult] readFunc, Microsoft.OData.ODataPayloadKind[] payloadKinds) [0x00030] in <3821c67bef1a4240aa87fa2afb20b4a9>:0 at Microsoft.OData.ODataMessageReader.ReadError () [0x00006] in <3821c67bef1a4240aa87fa2afb20b4a9>:0 at Microsoft.OData.Client.BaseSaveResult.GetResponseText (System.Func1[TResult] getResponseStream, System.Net.HttpStatusCode statusCode) [0x00084] in <37fe22d142124247b7abcad9baf83ea0>:0
at Microsoft.OData.Client.BaseSaveResult.HandleResponse (Microsoft.OData.Client.RequestInfo requestInfo, System.Net.HttpStatusCode statusCode, System.String responseVersion, System.Func1[TResult] getResponseStream, System.Boolean throwOnFailure, System.Version& parsedResponseVersion) [0x00037] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.QueryResult.CompletedRequest () [0x0006c] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.BaseAsyncResult.HandleCompleted () [0x0002a] in <37fe22d142124247b7abcad9baf83ea0>:0 --- End of inner exception stack trace --- at Microsoft.OData.Client.BaseAsyncResult.EndExecute[T] (System.Object source, System.String method, System.IAsyncResult asyncResult) [0x0014c] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement] (System.Object source, System.String method, System.IAsyncResult asyncResult) [0x00002] in <37fe22d142124247b7abcad9baf83ea0>:0 --- End of inner exception stack trace --- at Microsoft.OData.Client.QueryResult.EndExecuteQuery[TElement] (System.Object source, System.String method, System.IAsyncResult asyncResult) [0x00037] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.DataServiceRequest.EndExecute[TElement] (System.Object source, Microsoft.OData.Client.DataServiceContext context, System.String method, System.IAsyncResult asyncResult) [0x000a5] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.DataServiceContext.EndExecute[TElement] (System.IAsyncResult asyncResult) [0x0000c] in <37fe22d142124247b7abcad9baf83ea0>:0 at Microsoft.OData.Client.DataServiceActionQuerySingle1[T].EndGetValue (System.IAsyncResult asyncResult) [0x0000c] in <37fe22d142124247b7abcad9baf83ea0>:0
at System.Threading.Tasks.TaskFactory1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func2[T,TResult] endFunction, System.Action1[T] endAction, System.Threading.Tasks.Task1[TResult] promise, System.Boolean requiresSynchronization) [0x0000f] in /Users/builder/jenkins/workspace/archive-mono/2019-10/android/release/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/FutureFactory.cs:534
--- End of stack trace from previous location where exception was thrown ---

Code I use on the OData service side for the "test".

// Add this to the Application_Start() inside the global asx if using ASP.NET non-core
HttpConfiguration config = GlobalConfiguration.Configuration;
config.Filters.Add(new TestExceptionFilterAttribute());


public class TestExceptionFilterAttribute : ExceptionFilterAttribute
{
	public override void OnException(HttpActionExecutedContext context)
	{
		HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.BadRequest);
		response.RequestMessage = context.Request;
		ODataError oDataError = new ODataError();

		if (context.Exception is OperationCanceledException && (context.Exception as OperationCanceledException).CancellationToken.IsCancellationRequested)
		{
			// eat this exception because user closed the web service while they were getting data                
			return;
		}
		else if (context.Exception is ValidationException)
		{
			oDataError.ErrorCode = "Validation";
			oDataError.Message = context.Exception.Message;
		}
		else if (context.Exception is DbEntityValidationException)
		{
			DbEntityValidationException dbVex = context.Exception as DbEntityValidationException;
			StringBuilder errorMessage = new StringBuilder();

			foreach (DbValidationError validationError in dbVex.EntityValidationErrors.FirstOrDefault().ValidationErrors)
			{
				errorMessage.AppendLine(validationError.ErrorMessage);
			}

			oDataError.ErrorCode = "Validation";
			oDataError.Message = errorMessage.ToString();
		}
		else if (context.Exception is SqlException && (context.Exception as SqlException).Number >= 50000)
		{
			// this is a SQL validation error
			oDataError.ErrorCode = "Validation";
			oDataError.Message = context.Exception.Message;
		}
		else
		{
			// we only care about the top most exception
			Exception tempError = context.Exception;
			string errorMessage = tempError.Message;
			while (tempError.InnerException != null)
			{
				tempError = tempError.InnerException;
				errorMessage = tempError.Message;
			}

			oDataError.ErrorCode = "Exception";
			oDataError.Message = errorMessage;

			// log the exception
				
			}
		}

		response.Content = new StringContent(JsonConvert.SerializeObject(oDataError));
		context.Response = response;
	}
}
	
	
// Use this to test ValidationException
throw new ValidationException("This is a validation test message!");
@ImGonaRot ImGonaRot changed the title In OData, a top-level error object must have exactly one property with name 'error' -- OData Client 7.6.4 OData Client 7.6.4 is getting this error "In OData, a top-level error object must have exactly one property with name 'error'" Apr 24, 2020
@maxvella
Copy link

maxvella commented Apr 26, 2020

Getting the same error on 7.6.4. 7.6.3 working fine.

I'm getting the following stack trace:

at Microsoft.OData.JsonLight.ODataJsonLightErrorDeserializer.ReadTopLevelErrorImplementation()
at Microsoft.OData.JsonLight.ODataJsonLightErrorDeserializer.ReadTopLevelError()
at Microsoft.OData.JsonLight.ODataJsonLightInputContext.ReadError()
at Microsoft.OData.ODataMessageReader.<>c.b__68_0(ODataInputContext context)
at Microsoft.OData.ODataMessageReader.ReadFromInput[T](Func2 readFunc, ODataPayloadKind[] payloadKinds) at Microsoft.OData.ODataMessageReader.ReadError() at Microsoft.OData.Client.BaseSaveResult.GetResponseText(Func1 getResponseStream, HttpStatusCode statusCode)
at Microsoft.OData.Client.BaseSaveResult.HandleResponse(RequestInfo requestInfo, HttpStatusCode statusCode, String responseVersion, Func`1 getResponseStream, Boolean throwOnFailure, Version& parsedResponseVersion)
at Microsoft.OData.Client.SaveResult.HandleOperationResponseData(IODataResponseMessage responseMsg, Stream responseStream)
at Microsoft.OData.Client.SaveResult.FinishCurrentChange(PerRequest pereq)
at Microsoft.OData.Client.BaseSaveResult.AsyncEndRead(Task task, Object asyncState)

With the following error message ODataException: A property with name 'type' was found in the error object when reading a top-level error. In OData, a top-level error object must have exactly one property with name 'error'.

@marabooy marabooy added bug client only related to OData.Client P2 regression labels Apr 28, 2020
paulodero added a commit to paulodero/odata.net that referenced this issue May 6, 2020
mikepizzo added a commit that referenced this issue May 7, 2020
commit 182964d
Author: Sreejith Pazhampilly <[email protected]>
Date:   Wed May 6 21:39:03 2020 -0700

    Fix E2E Tests

commit 565ccdc
Author: Sreejith Pazhampilly <[email protected]>
Date:   Thu Apr 30 11:03:23 2020 -0700

    Update to net core 2.1 and 3.1 for UT

commit afeb7d8
Author: Sreejith Pazhampilly <[email protected]>
Date:   Tue Apr 28 16:33:36 2020 -0700

    Make the CI working

commit d844d4a
Author: Sam Xu <[email protected]>
Date:   Thu Apr 23 22:09:17 2020 -0700

    Update the test case projects

commit 26709dd
Author: Sreejith Pazhampilly <[email protected]>
Date:   Thu Apr 23 12:09:39 2020 -0700

    updates , pipeline changes

commit 21a1d3d
Author: Sam Xu <[email protected]>
Date:   Wed Apr 22 18:27:12 2020 -0700

    Modify the unit test case, fix the waring, fix the version, etc

commit 82f949d
Author: Sam Xu <[email protected]>
Date:   Wed Apr 22 15:01:40 2020 -0700

    update the build CI and project

commit c9fae43
Author: Sam Xu <[email protected]>
Date:   Tue Apr 21 15:21:30 2020 -0700

    Clean up the codes

commit 6c50be0
Author: Sam Xu <[email protected]>
Date:   Tue Apr 21 14:56:13 2020 -0700

    With whole project changes

commit 77d9f88
Author: Paul Odero <[email protected]>
Date:   Thu May 7 10:52:23 2020 +0300

    Fix #1756 (#1764)- Reading OData Error Response in OData Client

commit 5a20f51
Author: Sam Xu <[email protected]>
Date:   Mon May 4 16:10:36 2020 -0700

    Resolve the product code build warnings

commit 26739c1
Author: Sam Xu <[email protected]>
Date:   Mon May 4 13:48:50 2020 -0700

    Fix WebApi issue OData/WebApi#2136: IN operator with double quote fails

commit 44ed8db
Author: Paul Odero <[email protected]>
Date:   Mon Apr 27 11:52:23 2020 +0300

    Fixing issue #794 (#1656)

commit e0e628a
Author: Paul Odero <[email protected]>
Date:   Mon Apr 27 09:36:08 2020 +0300

    Enable OData client to send IEEE754Compatible parameter in the reques… (#1659)

    * Fixes #725 and also fixes #522

commit a398670
Author: Sam Xu <[email protected]>
Date:   Fri Apr 17 11:48:34 2020 -0700

    Fix some build warning in Edm lib

commit 82ed887
Author: Clément Habinshuti <[email protected]>
Date:   Wed Apr 15 13:39:56 2020 +0300

    Add support for relative uris and absolute uris with host header in json batch requests (#1740)

commit b17d455
Author: Clément Habinshuti <[email protected]>
Date:   Wed Apr 15 11:40:01 2020 +0300

    Update error message when adding unsupported query option (#1729)

    * Update error message when adding unsupported query option

    * Update string resources in portablelib

    * Fix resource string errors in portable lib

    * Update error message

    * Remove references to unused error message

    * Fix failing tests

    * Fix typo

commit d3769fd
Author: John Gathogo <[email protected]>
Date:   Thu Apr 9 10:55:38 2020 +0300

    Fix bug where open types are not identified as such during serialization (#1727)

    * Fix bug where open types are not identified as such during serialization

    Remove unnecessary assert

    * serviceModel may be initialized from 2 locations. Ensure both trigger population of edm structured elements

    Co-authored-by: John Gathogo <[email protected]>

commit 80e73d0
Author: KanishManuja-MS <[email protected]>
Date:   Fri Apr 3 10:10:43 2020 -0700

    Revert "ODataMessageWriter can't dispose the stream if there's no write method called (#1714)"

    This reverts commit 3e02e30.

# Conflicts:
#	test/FunctionalTests/Microsoft.OData.Core.Tests/ScenarioTests/Writer/JsonLight/ODataJsonLightInheritComplexCollectionWriterTests.cs
@tomaszbroniewski
Copy link

I'm getting the similar error but with 'innerError' indication (OData Client 7.6.4)

ODataException: A property with name 'innerError' was found in the error value of a top-level error. In OData, a top-level error value can only have properties with name 'code', 'message', or 'innererror', or custom instance annotations.

@paulodero
Copy link
Contributor

I'm getting the similar error but with 'innerError' indication (OData Client 7.6.4)

ODataException: A property with name 'innerError' was found in the error value of a top-level error. In OData, a top-level error value can only have properties with name 'code', 'message', or 'innererror', or custom instance annotations.

This was fixed. Should work well in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug client only related to OData.Client P2 regression
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants