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

前端 未结 8 1652
天命终不由人
天命终不由人 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:45

    In my case the object being returned had a property within it with a type that did not have an argumentless/default constructor. By adding a zero-argument constructor to that type the object could be serialized successfully.

提交回复
热议问题