Thursday, March 29, 2007

Dataset JSON Serialization

There definitely seems to be some problem serializing dataset in the latest 'RELEASE' version of ASP.NET

It keeps on giving some 'Circular Reference Error' while deserializing a ASP.NET dataset.

After lot of researching on the web , this is how I solved it

1. Downloaded ASP.NET ATLAS JAN CTP from here:

2. Added reference to Microsoft.Web.Preview.dll

3.Added following lines to web.config

<converters>
<add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/>
<add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/>
</converters>


4. My web service returns a typed dataset with ID and Name columns.

Now these javascript lines work:

result.tables[0].rows[0].ID
result.tables[0].rows[0].Name

1 comment:

Unknown said...

Can you post your code that calls JavaScriptSerializer passing a dataset and returning the JSON string? I'm having some problems with this and need some help. Thanks!


Site Meter