Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You seem to be using ASMX (not WCF) because you have omitted <code>[DataMember]</code> attributes on all your public properties and still get serialized. WCF is "opt-in", so you shouldn't be seeing any serialization of any properly.</p> <p>As a result, all <code>[DataContract]</code> attributes are useless.</p> <p>ASMX defaults to the JavaScriptSerializer if you are using ScriptManger and outputing JSON. The JavaScriptSerializer is "opt-out" (which means that all public properties are automatically serialized unless marked with <code>[ScriptIgnoreAttribute]</code>).</p> <p>The JavaScriptSerializer supports serializing List&lt;>'s. You should not be having problems serializing your TestCol property because JavaScriptSerializer automatically supports serializing all types that implement IEnumerable (but not IDictionary) -- which includes List&lt;> -- into JSON arrays.</p> <p>Your error seems to be that the JavaScriptSerializer does not properly handle classes that <em>inherit</em> from List&lt;> (or from a class implementing IEnumerable). In your first work-around, you eliminated the class that inherited from List&lt;>. In your second work-around, you skipped all functionalities of the base class, but re-implemented the List&lt;> in a property.</p> <p>Your JSON post data currently looks like:</p> <pre><code>{ Components: [ { Name:"foo" }, { Name:"bar" }, : ] } </code></pre> <p>However, you have one extra level or redirection in the serializer (inheriting from <code>List&lt;Test&gt;</code> -> <code>TestCol</code>). It is possible that the serializer is looking for:</p> <pre><code>{ Components: { Items: [ { Name:"foo" }, { Name:"bar" }, : ] } } </code></pre> <p>because you are essentially serializing the "Items" property of List&lt;>. So, your JSON post data is just feeding Test objects to the wrong place, and your TestCol Components property ends up empty.</p> <p>I'd suggest that you add a web service method to output a test MainTest object to see what it serializes into. You'll probably find that it puts in an additional level.</p>
 

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