The system.invalidoperationexception exception is reported when a data object is serialized using LINQ to SQL and a circular reference is detected when serializing an object of type XXX.

Source: Internet
Author: User

This article originates from: http://www.cnblogs.com/zhhh/archive/2011/04/06/2006868.html

A circular reference is detected when a data object is serialized using LINQ to SQL and a System.InvalidOperationException exception is reported, and an object of the type is serialized.

Exception information (partial):

System.Web.Services.Protocols.SoapException: The server was unable to process the request. ---> System.InvalidOperationException: An error occurred while generating the XML document. ---> System.InvalidOperationException: A circular reference is detected when serializing an object of type Web.DAL.Friends.

(slightly later)

This means that when using LINQ to SQL, there is an association between the table and the table, which produces an infinite cyclic reference when serializing these related data objects.

Here we can fix this problem by configuring the DataContext file.

First we open the DataContext file, set the "Serialization mode" property to "single" in the file's Properties window,

Then in the view of the DataContext file, select the relationship between the table and the table, and set the properties of the relationship. In the Properties window, set the value of the access permission property under the parent Properties node to internal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.