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

前端 未结 8 1662
天命终不由人
天命终不由人 2020-11-27 16:56

Simplest example of this, I get a collection and try to output it via Web API:

// GET api/items
public IEnumerable Get()
{
    return MyContext.I         


        
8条回答
  •  广开言路
    2020-11-27 17:29

    I just disabled proxy classes on a per needed basis:

        // GET: ALL Employee
        public IEnumerable Get()
        {
            using (AdventureWorks_MBDEV_DW2008Entities entities = new AdventureWorks_MBDEV_DW2008Entities())
            {
                entities.Configuration.ProxyCreationEnabled = false;
                return entities.DimEmployees.ToList();
            }
        }
    

提交回复
热议问题