3

我有一个奇怪的问题,我无法解决。我正在尝试为我的 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<> 在反序列化期间可能会抛出循环引用,因为组不一定具有唯一的行引用。

我的问题是为什么它在本地运行良好?我不知道我错过了什么。

4

1 回答 1

2

[ScriptIgnore]属性有帮助真是太好了。此外,要完全确定的是,您的所有 URL 路径(包括 AJAX 代码)都正确解析为应用程序根目录。当其中一些错误时,这是​​从开发到生产过程中臭名昭著的问题来源。

听起来这不一定是主要问题,但我对您的应用程序的设计没有任何了解。绝对值得一看。

于 2014-01-20T22:23:17.520 回答