Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A circular reference was detected while serializing an object of type System.Globalization.CultureInfo

I'm using jquery to call a webservice which returns a dataset with a couple of tables in it.

This was working ok until i needed to set up my webmethod to accept a parameter. I reflected this on the client side with

data: "{paramname:'" + paramval+ "'}",

I now get the following error when the webmethod returns. This happens regardless of whats being returned in the dataset

Error:{"Message":"A circular reference was detected while serializing an object of type \u0027System.Globalization.CultureInfo\u0027.","StackTrace":" at System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat)\r\n at ...etc

When the webmethod has no parameters the client side js looks the same as below except the data: line is removed.

function ClientWebService(paramval){
$.ajax({
    type: "POST",
    url: "WebService1.asmx/webmethodName", 
    data: "{paramname:'" + paramval+ "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
        ParseResult(msg.d);
    },
    error: function(err) {
        if (err.status == 200) {
              ParseResult(err);
        }
        else { alert('Error:' + err.responseText + '  Status: ' + err.status); }
    }
}); 

}

Edit: As per suggestion to change the request to

data: {paramname: paramval},

yields the following error.

Error:{"Message":"Invalid JSON primitive: paramval.","StackTrace":"
at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject()\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.ArgumentException"} Status: 500

like image 540
user48408 Avatar asked Mar 23 '09 11:03

user48408


2 Answers

I changed my webmethod to return

ds.GetXml();

and this worked. Considering datasets are serializeable I'm not sure why I have to do this, but it gets me over this hurdle.

like image 77
user48408 Avatar answered Sep 21 '22 05:09

user48408


I had the exact same problem,

I removed Virtual keyword from my Entities which make lazy loading of object.

The problem solved!!

like image 20
BlueBird Avatar answered Sep 22 '22 05:09

BlueBird