AspNetCoreOData icon indicating copy to clipboard operation
AspNetCoreOData copied to clipboard

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

Open ckashyap91 opened this issue 2 years ago • 5 comments

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?

ckashyap91 avatar Jun 08 '23 19:06 ckashyap91

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

KenitoInc avatar Jun 13 '23 17:06 KenitoInc

Yes @KenitoInc

ckashyap91 avatar Jun 13 '23 19:06 ckashyap91

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

okutbay avatar Jan 04 '24 22:01 okutbay

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?

julealgon avatar Jan 16 '24 21:01 julealgon

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.

okutbay avatar Jan 16 '24 21:01 okutbay