Note that there are some explanatory texts on larger screens.

plurals
  1. PO"The EntityReference object could not be serialized" when serializing from an ASP.NET Web Site, but works OK on an ASP.NET Web Application
    primarykey
    data
    text
    <p>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.</p> <p>To test this, I created a new ASP.NET web <em>Application</em>, (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:</p> <pre><code>var client = new CustomerServiceClient(); var customer = client.GetCustomerByID(18); // get it customer.LimitDown = 100; // change it client.SaveCustomer(customer); // persist it </code></pre> <p>Everything works as expected.</p> <p>Now, I do exactly the same thing, but this time with as ASP.NET Web <em>Site</em> (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:</p> <blockquote> <p><strong>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.</strong></p> <p>Source Error: </p> <p>Line 2474: Line 2475:<br> public SkyWalkerCustomerService.OperationResult SaveCustomer(SkyWalkerCustomerService.Customer customer) { Line 2476:<br> return base.Channel.SaveCustomer(customer); Line 2477: } Line 2478: }</p> <p>Stack Trace: </p> <p>System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9475203<br> System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type) +345<br> SkyWalkerCustomerService.ICustomerService.SaveCustomer(Customer customer) +0<br> 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<br> System.Web.UI.Control.OnLoad(EventArgs e) +91<br> System.Web.UI.Control.LoadRecursive() +61 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1966</p> </blockquote> <p>Googling for this error returns very little. Why doesn't this work?</p> <p>I guess one answer would be to use a web application instead of a web site, but I have an large existing site to which I need to add the service reference, and I'd rather not convert it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload