Weird - "The EntityReference object could not be serialized" when serializing from an ASP.NET Web Si
Posted
by Mikey Cee
on Stack Overflow
See other posts from Stack Overflow
or by Mikey Cee
Published on 2010-03-22T04:21:49Z
Indexed on
2010/03/22
4:31 UTC
Read the original article
Hit count: 838
I have an Entity Framework data model. Part of the model is a Customer entity. The web service provides a method to get a customer, and to receive an updated version of this customer to be persisted.
To test this, I created a new ASP.NET web Application, (Solution > Add > New Project > ASP.NET Web Application), then added a reference to my service reference using the standard Add Service Reference dialog. I then call the service using the following code:
var client = new CustomerServiceClient();
var customer = client.GetCustomerByID(18); // get it
customer.LimitDown = 100; // change it
client.SaveCustomer(customer); // persist it
Everything works as expected.
Now, I do exactly the same thing, but this time with as ASP.NET Web Site (Solution > Add > New Web Site > ASP.NET Web Site). I add the reference in a similar fashion and copy and paste the code above into the new site. But now I get the following exception thrown on the 4th line:
System.InvalidOperationException The EntityReference object could not be serialized. This type of object cannot be serialized when the RelationshipManager belongs to an entity object that does not implement IEntityWithRelationships.
Source Error:
Line 2474: Line 2475:
public SkyWalkerCustomerService.OperationResult SaveCustomer(SkyWalkerCustomerService.Customer customer) { Line 2476:
return base.Channel.SaveCustomer(customer); Line 2477: } Line 2478: }Stack Trace:
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9475203
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
SkyWalkerCustomerService.ICustomerService.SaveCustomer(Customer customer) +0
SkyWalkerCustomerService.CustomerServiceClient.SaveCustomer(Customer customer) in c:\Windows\Microsoft.NET\Framework\v4.0.30128\Temporary ASP.NET Files\testsite2\dd2bcf8d\f95604ff\App_WebReferences.fz4h7x7l.0.cs:2476 _Default.Page_Load(Object sender, EventArgs e) in c:\Users\Mike\Documents\Repositories\UWC\SkyWalker\TestSite2\Default.aspx.cs:17 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +61 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1966
Googling for this error returns very little. Why doesn't this work?
© Stack Overflow or respective owner