On the client side an object 'selectedMeter' is build in JavaScript. This object is send to the server with an ajax call and passed to the mvc controller.
$.ajax({
url: 'SaveManualMeter',
type: "POST",
cache: false,
contentType: "application/json; charset=utf-8",
data: **JSON.stringify({ clientId: selectedClientId, manualMeter: selectedMeter** }),
complete: function () {
When tested locally, it works, however when the site is published, it throws an error A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
- [InvalidOperationException: A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.]
- System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +1856
- System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat, MemberInfo currentMember) +266
- System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o, StringBuilder sb, Int32 depth, Hashtable objectsInUse, SerializationFormat serializationFormat) +668
The controller look like this
public ActionResult
SaveManualMeter(string clientId, ManualMeter manualMeter)
Does someone knows what the problem is?
The structure of manualmeter looks like
[JsonObject(IsReference = false)]
public class ManualMeter
{
public int Id { get; set; }
public string Ean { get; set; }
public PeriodType Period { get; set; }
public string TagTable { get; set; }
public string TagTableId { get; set; }
public int Overflow { get; set; }
public string TZ { get; set; }
public DataLogger DataLogger { get; set; }
public Tag Tag { get; set; }
public List<ManualMeterAction> ManualMeterActions { get; set; }
}
public class ManualMeterAction
{
public int Id { get; set; }
public ManualMeterActionType Type { get; set; }
//navigation properties
public int ManualMeterId { get; set; }
public int UserId { get; set; }
}
raw json object that is posted seems ok
{"clientId":"11","manualMeter":{"Tag":{"Name":"22","Unit":"Unknown","TagType":"0","Content":"1"},"Id":0,"Ean":"","ManualMeterActions":[],"Period":"0","Overflow":"22","TZ":"Europe/Brussels"}}