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

后端 未结 2 1727
谎友^
谎友^ 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:21

    If you don't need the lazy-loaded navigation properties provided by the proxy class (System.Data.Entity.DynamicProxies.Student_4C97D068E1A...), you can disable their generation by setting:

    unitOfWork.Configuration.ProxyCreationEnabled = false;
    

    What to do if you need the proxy class is another question.


    Follow these links for a good overview of lazy loading and proxies:

    • Loading Related Entities
    • Working with Proxies
    • Should I enable or disable dynamic proxies

    I usually disable lazy loading and proxies by default, and enable one or both in specific code blocks that need them.

提交回复
热议问题