0

When overriding the ContractResolver Per Controller and responding with EF code first models with DynamicProxies

public virtual ICollection<Dealer>

I get the following error:

Der Typ 'System.Data.Entity.DynamicProxies.Category_3A79660F329089EEB63C385A2604922D659127A759AE76F676297AF7DC53A144' mit dem Datenvertragsnamen 'Category_3A79660F329089EEB63C385A2604922D659127A759AE76F676297AF7DC53A144:http://schemas.datacontract.org/2004/07/System.Data.Entity.DynamicProxies' wird nicht erwartet. Verwenden Sie ggf. einen DataContractResolver, wenn Sie DataContractSerializer verwenden, oder fügen Sie alle unbekannten Typen statisch der Liste der bekannten Typen hinzu, beispielsweise mithilfe des KnownTypeAttribute-Attributs oder indem Sie sie zur Liste der bekannten Typen hinzufügen, die an das Serialisierungsprogramm übergeben wird.

The only thing I'm changing in the initialize method is:

controllerSettings.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

Running the same code in the OWIN startup class works perfect.

I do not want to solve this problem by just disabling EF proxies:

DbContext.Configuration.ProxyCreationEnabled = false;
  • Without that change everything works fine, right? – Roman Marusyk Feb 11 '18 at 20:41
  • Possible duplicate of [The 'ObjectContent\`1' type failed to serialize the response body for content type in WebAPI](https://stackoverflow.com/questions/28150187/the-objectcontent1-type-failed-to-serialize-the-response-body-for-content-typ) – Roman Marusyk Feb 11 '18 at 20:43
  • This would work - but just by disabling the EF proxy classes. I want to keep them _but_ be able to serialize them. – user3640273 Feb 11 '18 at 20:55

0 Answers0