私はメソッドを持っています。これは行にExecuteResult
a を投げています。これは、オブジェクトが;に対してメモリ内で大きすぎるために発生しています。それはメモリをいっぱいにします。System.OutOfMemoryException
Response.Write(sw.ToString())
StringWriter
ToString
私は解決策を探していましたが、問題に対する単純でクリーンな解決策を見つけることができないようです。どんなアイデアでも大歓迎です。
コード:
public class JsonNetResult : JsonResult
{
public JsonNetResult()
{
Settings = new JsonSerializerSettings
{
ReferenceLoopHandling = ReferenceLoopHandling.Error
};
}
public JsonSerializerSettings Settings { get; private set; }
public override void ExecuteResult(ControllerContext context)
{
if (this.Data != null)
{
if (context == null)
throw new ArgumentNullException("context");
if (this.JsonRequestBehavior == JsonRequestBehavior.DenyGet && string.Equals(context.HttpContext.Request.HttpMethod, "GET", StringComparison.OrdinalIgnoreCase))
throw new InvalidOperationException("JSON GET is not allowed");
HttpResponseBase response = context.HttpContext.Response;
response.ContentType = string.IsNullOrEmpty(this.ContentType) ? "application/json" : this.ContentType;
if (this.ContentEncoding != null)
response.ContentEncoding = this.ContentEncoding;
var scriptSerializer = JsonSerializer.Create(this.Settings);
using (var sw = new StringWriter())
{
scriptSerializer.Serialize(sw, this.Data);
//outofmemory exception is happening here
response.Write(sw.ToString());
}
}
}
}