JSON反序列化只抛出活构建循环引用 [英] JSON deserialization throws circular reference ONLY in live build

查看:200
本文介绍了JSON反序列化只抛出活构建循环引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,我不能绕到我的头。我想对于其中有关JSON是通过Ajax调用我的ActionResult通过我MVC4应用程序创建一个导出为CSV格式功能。该的ActionResult反序列化stringify'd JSON(与JSON.Net),它写入到CSV格式的文件,然后返回服务器路径,新的文件。我的成功回调然后接收路径,并呼吁要下载的URL。

I have a strange issue that I can't wrap my head around. I am trying to create an "export to csv" function for my MVC4 application where the relevant JSON is passed via an ajax call to my ActionResult. The ActionResult deserializes the stringify'd JSON (with JSON.Net), writes it to a file in csv format, then returns the server path to the new file. My success callback then receives the path and calls the url to download.

这工作正常本地,但我的现场测试服务器上我得到以下异常:

This works fine locally, but on my live test server I get the following exception:

在序列化类型'System.Reflection.RuntimeModule'。

的JSON(随后他们被反序列化的对象)稍微复杂。他们来自一个SlickGrid数据视图的分组子集。当我列入列总计的汇总信息我得到循环引用异常(这只是那些在SlickGrid精通相关的,我不相信传递的数据到服务器是一个问题),但我已经把他们赶走前传递JSON来服务器。这里是我的JSON到C#类结构:

The JSON (and subsequently the objects they are deserialized to) are slightly complex. They come from a grouped subset of a SlickGrid DataView. I was getting circular reference exceptions when I included the aggregate information for column totals (this is only relevant to those that are versed in SlickGrid, I do not believe the data being passed to the server is an issue), but I've removed them before passing the JSON to the server. Here is my JSON to C# class structure:

[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; }
}

这是我想的唯一一件事是,因为方式的数据结构,列表和LT;在根对象中的行>可能是deserializtion期间投掷循环引用,因为一组不一定有唯一的行引用。

The only thing that I'm thinking is that, because of the way the data is structured, the List<> of rows in the root object may be throwing the circular references during deserializtion because a group does not necessarily have unique row references.

我的问题是,为什么它的工作原理局部精细?我不知道我错过了什么。

My question is why does it work fine locally?? I have no idea what I'm missing.

推荐答案

这是伟大的,在 [ScriptIgnore] 属性帮助。此外,一些是完全肯定的是,所有的URL路径,包括在你的AJAX code,正确解析应用程序根目录。当其中一些是错误的,这是从开发迁移到生产过程中的问题,一个臭名昭著的根源。

That's great that the [ScriptIgnore] attribute is helping. Also, something to be completely sure of is that all of your URL paths, including in your AJAX code, resolve correctly to the application root. When some of these are wrong, this is a notorious source of problems during the move from development to production.

这听起来并不像它必然是首要的问题,但我没有你的应用程序设计的任何理解。这绝对是值得期待了。

It doesn't sound like it is necessarily the primary issue but I don't have any understanding of your app's design. It's definitely worth looking over.

这篇关于JSON反序列化只抛出活构建循环引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆