Wednesday, March 28, 2012

Ajax beta2 -> RTM > JSON Serialization exception when calling a dataservice

Hi all, I must migrate an application from Ajax beta2 to RTM version and I experienced a serious problem.This application uses xml-script that calls some webservices (more specifically dataservices) to fill in objets. These calls throw json serialization exceptions, whatever the returned type.I then wanted to try with a "fresh" web project, I thus created a new project, and then created a small web service inherited from the dataservice class. I placed a typical example of a sample dataservice from internet into my dataservice. Then I used Fiddler to emulate the dataservice call from the script (ie doing a POST with loadmethod parameters etc…), and this simple code produces a serialization exception.The only information I found is herehttp://www.oreilly.com/catalog/atlas/update/version1.0-update.pdf (chapter 9). This chapter is about the same subject, and the author is experience the same trouble in the same circumstances. Christophe Below is the complete exception:

{"Message":"A circular reference was detected while serializing an object of type \u0027System.Reflection.Module\u0027.","StackTrace":" à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse)\r\n à System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n à System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

The latest release does not support DataSet, DataTables or the Xml Script. You have to add the Preview to work with these objects.


Have you install framework 2.0?


I am using Microsoft.Web.Preview from the the "ASP.NET Futures May 2007" package (assembly version 1.1.61025.0).

I do not use complex objets like Dataset, Datatables,...

The sample code was picked up fromhttp://aspalliance.com/1302_Unveil_the_Data_Binding_Architecture_inside_Microsoft_ASPNET_Ajax_10__Part_2#Page2, but even a string does not serialize !

Note that the call stack shows an exception within System.Web.Script.Serialization, which is in Ajax Extensions, not in futures ...

Christophe.


No, we have no answer at this time.


Hi chrisrodri,

Has your problem been resolved yet ? Would you share your solution(resolved) or new findings?


Hi all,

I finally solved this issue. I have to add these threw following lines into the web.config (in jsonSerialization/converters section):

<addname="DataSetConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter"/>
<addname="DataRowConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter"/>
<addname="DataTableConverter"type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter"/>

I do not understand why these lines are needed because i do not use any DataTable or DataRow, just generics Lists that are not dependant of these ones.... but it works !

No comments:

Post a Comment