NANDAKUMAR THANGAVELU
NANDAKUMAR THANGAVELU

Reputation: 661

Getting an error on request

I am new to Web API. I just want to return some List on some method call, in which its verb is HttpGet.

Upon giving the request in the browser, I have received the following error:

Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'

I have searched for the solution, and finally,

DBContextObjName.Configuration.ProxyCreationEnabled = false;

is the one, which solves the error.

But I just want to know, how this solves the error. I mean in which way the solution and the error related.

May I kindly know, the explanation for it. So I can understand this, more clearly.

Thanks in advance.

Upvotes: 1

Views: 40

Answers (1)

Nkosi
Nkosi

Reputation: 247641

According to MSDN DbContextConfiguration.ProxyCreationEnabled Property

Gets or sets a value indicating whether or not the framework will create instances of dynamically generated proxy classes whenever it creates an instance of an entity type. Note that even if proxy creation is enabled with this flag, proxy instances will only be created for entity types that meet the requirements for being proxied. Proxy creation is enabled by default.

Knowing that if you look at a few others who had similar issue

Failed to serialize the response in Web API with Json

failed to serialize the response in Web API

Asp.Net Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type 'application/xml; charset=utf-8'

The dynamically generated proxy classes cannot be serialized has issues when formatters try to serialize it.

Some cases mentioned circular references associated navigation properties.

Upvotes: 2

Related Questions