DataContractSerializer Error using Entity Framework 4.0 with WCF 4.0
When using the DbContext API for Code First (EF 4.3) I had to do:
public class MyClass : DbContext
{
public MyClass()
{
base.Configuration.ProxyCreationEnabled = false;
}
}
For EntityFramework 6.0 I had to change configuration as well:
public class MyContext : DbContext
{
public MyContext() : base("name=MyContext")
{
Configuration.ProxyCreationEnabled = false;
}
}
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.