OData / AspNetCoreOData

ASP.NET Core OData: A server library built upon ODataLib and ASP.NET Core
Other
458 stars 159 forks source link

Type Microsoft.OData.Edm.EdmModel is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer #952

Open ckashyap91 opened 1 year ago

ckashyap91 commented 1 year ago

Version: 8.0.12 MongoDB.Driver: 2.19.2 MongoDB.Entities: 22.0.0

I am using MongoDB to create Odata service. Here are my API and entity object image

image

The issue currently while using https://localhost:7119/odata/Supplier?select=Name select for mongo db collection. It is throwing an error for mongo db. I am not sure is a mongo db package issue or if something needs to configure for OData. BsonSerializationException: Type Microsoft.OData.Edm.EdmModel is not configured as a type that is allowed to be serialized for this instance of ObjectSerializer.

image

Can anyone guide here on what can be an issue here?

KenitoInc commented 1 year ago

Do you get the correct results when you don't apply a $select query option? i.e GET https://localhost:7119/odata/Supplier

ckashyap91 commented 1 year ago

Yes @KenitoInc

okutbay commented 10 months ago

https://stackoverflow.com/a/75637412/234440

julealgon commented 10 months ago

https://stackoverflow.com/a/75637412/234440

Are you posting this as a potential solution to the problem @okutbay ? Can you provide some context to go along with your link comment?

okutbay commented 10 months ago

Hi @julealgon, yes that link has the solution to this problem. So mongodb driver added a configuration requirement to Serialize objects. You need to define explicitly which objects can be serialized. Otherwise you keep getting this error.