Web API Error: The 'ObjectContent`1' type failed to serialize the response body for content type

后端 未结 2 1733
谎友^
谎友^ 2021-01-03 07:10

I am getting this error when attempting to use a Web API controller.

Web API Error: The \'ObjectContent`1\' type failed to serialize the response body

2条回答
  •  渐次进展
    2021-01-03 07:26

    What is the inner exception message? The inner exception message will be the actual exception that is thrown by the serializer and it should tell us which type is causing the exception.

    Let me guess -- Is it any the type Course and the type Group? If so, try putting KnownType attribute on the actual implementation type of your class Student

    [KnownType(typeof(GroupA))]
    [KnownType(typeof(CourseA))]
    public partial class Student
    {...}
    
    public class GroupA : Group {...}
    public class CourseA : Course {...}
    
    public interface Group {...}
    public interface Course {...}
    

提交回复
热议问题