DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0

前端 未结 5 1711
灰色年华
灰色年华 2020-12-01 03:14

I am attempting to retrieve a list of objects from Entity Framework via WCF, but am receiving the following exception:

There was an error while trying to serialize p

5条回答
  •  误落风尘
    2020-12-01 04:03

    This was a pain to figure out but it is because EntityFramework creates a 'proxy' of your class. The TestObject class I had was setup correctly, but it was creating a class called: TestObject_240F2B681A782799F3A0C3AFBE4A67A7E86083C3CC4A3939573C5410B408ECCE

    To make the ChannelFactory + WCF + Entity Framework all work together, you must go into your Context constructor and add the following:

    ContextOptions.ProxyCreationEnabled = false;
    

    I hope this helps someone else.

提交回复
热议问题