我有一个奇怪的问题,我无法理解。我正在尝试为我的 MVC4 应用程序创建一个“导出到 csv”函数,其中相关的 JSON 通过 ajax 调用传递到我的 ActionResult。 ActionResult 反序列化字符串化的 JSON(使用 JSON.Net),将其写入 csv 格式的文件,然后返回新文件的服务器路径。然后我的成功回调会收到路径并调用 url 进行下载。
这在本地工作正常,但在我的实时测试服务器上我得到以下异常:
A circular reference was detected while serializing an object of type 'System.Reflection.RuntimeModule'.
JSON(以及随后反序列化为的对象)稍微复杂一些。它们来自 SlickGrid DataView 的分组子集。当我包含列总计的聚合信息时,我遇到了循环引用异常(这仅与那些精通 SlickGrid 的人相关,我不认为传递到服务器的数据是一个问题),但我已经删除了它们在将 JSON 传递到服务器之前。这是我的 JSON 到 C# 类结构:
[Serializable]
public class Row
{
public int id { get; set; }
public DateTime DateCreated { get; set; }
public int RefNo { get; set; }
public string ClientName { get; set; }
public string Plate { get; set; }
public string Address1 { get; set; }
public int? ProductID { get; set; }
public string Product { get; set; }
public string S1 { get; set; }
public string S2 { get; set; }
}
[Serializable]
public class RootReportObject
{
public bool __group { get; set; }
public int level { get; set; }
public int count { get; set; }
public string value { get; set; }
public string title { get; set; }
public int collapsed { get; set; }
public List<Row> rows { get; set; }
public object groups { get; set; }
public string groupingKey { get; set; }
}
我唯一想到的是,由于数据的构造方式,根对象中的行的 List 可能会在反序列化期间抛出循环引用,因为组不一定具有唯一的行引用。
我的问题是为什么它在本地运行良好?我不知道我错过了什么。
太好了[ScriptIgnore]
属性有帮助。另外,需要完全确定的是,所有 URL 路径(包括 AJAX 代码中的 URL 路径)都会正确解析为应用程序根目录。当其中一些错误时,这就是从开发到生产的过程中出现问题的一个臭名昭著的根源。
听起来这不一定是主要问题,但我对您的应用程序的设计没有任何了解。这绝对值得一看。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)