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

.NET Client fails to parse responses where @odata.context starts with $metadata# #2314

Closed
AronHetLam opened this issue Feb 11, 2022 · 3 comments
Assignees

Comments

@AronHetLam
Copy link

AronHetLam commented Feb 11, 2022

OData .NET Client fails to parse responses where @odata.context relative path starts with $metadata#, which some services respond with. Eg. $metadata#Projects. Mocking a response with just Projects works fine.

Assemblies affected

OData .Net lib 7.10.0 in .NET 6

Reproduce steps

Try parse a Json response where @odata.context consists of a relative path starting with $metadata#

Expected result

The Json should be parsed into objects accordingly, just like if the @odata.context would be just eg Projects

Actual result

With multiple entity retrieval it throws

System.ArgumentOutOfRangeException: Length cannot be less than zero. (Parameter 'length')
   at System.String.Substring(Int32 startIndex, Int32 length)
   at Microsoft.OData.TypeUtils.ParseQualifiedTypeName(String qualifiedTypeName, String& namespaceName, String& typeName, Boolean& isCollection)
   ...

and with single entity retrieval it throws
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..

Additional detail

I saw issue #2132, which probably fixed relative paths without $metada#. This might be related.

@xuzhg
Copy link
Member

xuzhg commented Feb 14, 2022

@AronHetLam can you share more codes, your payload? or maybe it's better for us to dig more if you can share a repro?

@AronHetLam
Copy link
Author

AronHetLam commented Feb 15, 2022

I can't give you access to repo or endpoint, but here is a .NET project and mock json-server that demonstrates the issue we ran into.

It has 4 endpoints in swagger UI, where the first two result in the above mentioned excepitons, and the last two works as expected. Payloads are served from and found in serveOdata/OData.json

Example.zip

I'm not an expert in OData, but a service I need to use returns payloads where @odata.context are as in the first two mocked responses.

@ElizabethOkerio
Copy link
Contributor

fixed by this: #2313

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants