Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am building a website in ASP.NET MVC4 the application is linked with a webAPI. in both application and API I use a dbml LINQ to SQL file for the db connection and also serializing and deserializing. The application has no active db connection, so the dbml is only used for deserializing purposes.

Results from the webAPI are serialized by JSON.NET, which are always successfull. Example:

[{"$id":"1","ID_DepartmentSlot":2400,"SlotStart":"2013-04-29T21:00:00","SlotEnd":"2013-04-30T01:00:00","Created":"2013-04-29T11:00:40.837","Deleted":false,"ID_Staff":19,"ID_User":1,"SlotRemark":"test other day","Approved":true,"Notifications":[],"Staff":{"$id":"2","ID_Staff":19,"StaffDescription":"MUG-arts","Created":"2013-03-26T13:21:51.407","Deleted":false,"ID_Department":1,"Staff_Users":[],"DepartmentSlots":[]}}]

The problem arizes when I try to deserialize this JSON in the application. I get the known "Circular reference" error.

Options in the webAPI:

            wachtapplicatieDBDataContext db = new wachtapplicatieDBDataContext();
            db.ObjectTrackingEnabled = false;

            var dataoptions = new System.Data.Linq.DataLoadOptions();
            dataoptions.LoadWith<DepartmentSlot>(ds => ds.Staff);

In both API and application I use following serializing options:

JsonFormatter.MaxDepth = 2;
Newtonsoft.Json.ReferenceLoopHandling.Ignore;
Newtonsoft.Json.PreserveReferencesHandling.Objects;
Newtonsoft.Json.Formatting.None;
Newtonsoft.Json.NullValueHandling.Ignore;
Newtonsoft.Json.ObjectCreationHandling.Replace;
Newtonsoft.Json.MissingMemberHandling.Ignore;

Also, I don't get this problem on all deserialisation methods, only specific.. But i don't see where the problem rises... because the methods are all alike.

share|improve this question
    
What is the known Circular Reference error? At what point are you getting it? Do you have any details for the error? Can you move the data access layer into a separate project to avoid that? –  Joanna Turban May 3 '13 at 20:20
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.