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

I am using jquery to call a web service that returns a dataset with multiple tables in it.

This worked fine until I needed to configure my web method to accept the parameter. I reflected this on the client side with

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

Now I get the following error when returning a web method. This happens regardless of what is returned in the dataset.

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

If the web method has no parameters, the client js side looks the same as below, except for the data row: the row is deleted.

 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 requested, change the request to

 data: {paramname: paramval}, 

produces the following error.

Error: {"Message": "Invalid JSON primitive: paramval.", "StackTrace": "
in System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializePrimitiveObject () \ r \ n in System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal (Int32 depth) on System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasD Int32 depthLimit, JavaScriptSerializer serializer) \ r \ n in 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 in System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest (HttpContext context, JavaScriptSerializer serializer) \ r \ n on System.Web.Script.Services.RestHandler.GetRawParams (WebSata Method , HttpContext context) \ r \ n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall (HttpContext context, WebServiceMetho dData methodData) "," ExceptionType ":" System.ArgumentException "} Status: 500

+7
json jquery c # web-services
source share
5 answers

I changed my web method to return

 ds.GetXml(); 

and it worked. Given that the datasets are serializable, I'm not sure why I should do this, but it makes me overcome this obstacle.

+5
source share

I had the same problem

I removed the virtual keyword from my objects, which make the object lazy load.

The problem is solved!

+1
source share

this often happens when serializing objects with entities and entities. for example, if you have such a set

  public EntitySet<ProductCategory> Subcategories 

the serializer will go into the ProductCategory and try to serialize all the sets as well, often ending back to the original object and, therefore, creating a loop.

The best way to avoid this is to put [ScriptIgnore] and [NonSerialized] in the fields and [ScriptIgnore] on properties like this.

  [ScriptIgnore] [NonSerialized] private EntitySet<ProductCategory> _Subcategories; [ScriptIgnore] [Association(Storage = "_Subcategories", ThisKey = "ID", OtherKey = "ParentID")] public EntitySet<ProductCategory> Subcategories { get { return this._Subcategories; } set { this._Subcategories.Assign(value); } } 

Same thing in Refs

+1
source share

I know that this question was answered, but I ran into the same problem and thought that I should use what worked for me so that others can hope to solve this problem.

 data: JSON.stringify(Params), 

Using the JSON.stringify method, I got the required result

where params is {"key":"value"}

0
source share

I came across this answer when there was a server side exception for type conversion.

0
source share

All Articles