Wednesday, 26 September 2018

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

If Running a WebApi(also using Entity Framework) generates an Error with :

Exception Message:

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

ExceptionMessage Of Inner Exception: //It may Change in your Case
Type 'System.Data.Entity.DynamicProxies.Employee_24CA4E4B0F13FE40CFB3C932CBDA6A7A95E177B491C366CE6314ABBF16ACDF1D' with data contract name 'Employee_24CA4E4B0F13FE40CFB3C932CBDA6A7A95E177B491C366CE6314ABBF16ACDF1D:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' is not expected. Consider using a DataContractResolver if you are using DataContractSerializer or add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to the serializer.

Solution:
You need to Disable Dynamic Proxy Creation by following Command:

sampleDBEntities.Configuration.ProxyCreationEnabled = false;

Happy Coding !!!

No comments:

Post a Comment

SQL Audits

1. sys.server_audits What it is: Lists all server-level audit objects . An audit is the top-level object that defines: Where to wri...