Json converters lacking in Microsoft AJAX RTM

Having spent some time developing a project using a CTP version of Microsoft Ajax ("ATLAS" back in the day) I finally came to migrate the project to the RTM version.

After uninstalling the CTP release, and installing the RTM release I wasn't surprised to see the project no longer compile. But once the basic problems were fixed (mainly name changes, tag prefixes, and a new scriptservice attribute for your web service classes) I was still seeing errors in the application.

One of the main problems were errors of 'System.InvalidOperationException: A circular reference was detected ...' when calling a webservice that returned a DataTable or DataRow[]. The UI of this project was pretty much built on client-side calls to update and select data in this way, so suddenly I had a lot of select methods that stoped working (and in a project with 300+ stored procedures behind the scenes this was a headache!)

I expected a few niggles but what I didn't expect was that the Json converters for DataTable and DataRow were no longer included (DataSet too I guess, but I wasn't using that in this project).

I noticed that the references to the converters in the web.config were commented out and replaced with:

<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>

... 'that doesn't look right', I thought.

Having seen online that the January 2007 CTP release had solid Json converters included I decided to use these rather than write my own (although that does look interesting ).

It turned out to be not too hard to get this working.

All that is required is to replace the converter/add elements with those from the January CTP

<add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

And to add the January CTP Microsoft.Web.Preview.dll file to the bin directory of your project (or the Global Assembly Cache if you prefer).

To get file with the converters I had to download the Jan CTP, install on a virtual machine (I didn't want to run the CTP install after the RTM one) and copy the one file I wanted. To save you the hassle I have attached the file below.

I was using a pretty old beta and in some cases had to refer to column values via a getProperty method...

var jsColumnValue = row.getProperty("ColumnName");

...these had to change to directly accessing the column value as a property...

var jsColumnValue = row.ColumnName;

...which I prefer, even though it involved rather a lot of typing in this instance.

Hey presto, my javascript was able to see my data again. That was all I had to do to migrate this section of my project.

If you have the same problem with passing Data tables out of web services back to javascipt, then follow the tips above and all will be well

Author Dave Howard

I have been involved in IT development for the last 10 years - a lot of it around desktop applications and telecoms.

Comments

Still Doesn't work said:

I have been trying this all day and when I try to serialize the dataset I get the circular reference error.

27/Dec/2007 21:03 PM

Add Comment

Name
Comment
 

Your comment has been received and will be shown once it passes moderation.