I have a table that references a child table with reference to parent (!), I am using LINQ to SQL, for a paricular scenario, when I want to serialize my result using Json(obj) in my controller code, I got an error saying.. “A circular reference was detected while serializing an object of type..” This issue is very well explained by Rick Strahl in his blog (link here) If we are using WCF services, setting SerializationMode …
5 articles Tag JSON
Gettting ClientIDs of asp.net controls in an external javascript file
When maintaining external javascript files for our webpages the biggest hurdle we face is the getting clientID of our server side controls in the javascript file. Let me demonstrate a workwround for this that I usually adopt. Step 1: In the page load event create an array of json objects representing the clIentIDs of all the controls that we would be requiring to use in javascript functions. Store this in a javascript global variable using window::onload …
Which JSON Serializer to use?
This is an easy one, but just want to make a note for easy reference. JSON is more ubiquitous than ever these days in ASP.Net web development. From AJAX enables web sites to MVC AJAX, JSON is “the” data-interchange format we want to use. There are 2 possible class libraries that you can use in ASP.net to serialize objects to JSON and back. If you are using WCF and your custom objects are marked as …
Tip: C# Automatic Properties, k_BackingField and JSON
If you are using automatic properties to define your data objects and you are trying to serialize these objects to a JSON string using DataContractSerializer (WCF/3.5), make sure you mark your data classes with [DataContract] and [DataMember] attributes (even if you are not really using WCF), a simple [Serializable] attribute will not do. If you just use [Serializable], the emitted JSON string will have a prefix tag “k_backingField” and the string is all mumbo-jumbo! So …
Using JSON – Some observations
When using JSON with Web Services (classic web service or WCF service), you might get an error “JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.” when your json string is too big. If you are using JavaScriptSerializer class to serilaize your object, then there is a property ser.MaxJsonLength that you can set to allow for more size. But somehow, I still got the error, and I had to …

Recent Comments