簡體   English   中英

輸出大型JSon對象和System.OutOfMemoryException

[英]Output large JSon object and System.OutOfMemoryException

我需要在ASP.NET(IIS7)應用程序中以JSON響應的形式發送二進制數據(文件)的響應,為此我使用System.Net.Json(與.NET 4.x一起提供)中的JsonObject對象。 不幸的是,有時我內存不足異常。

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Text.StringBuilder.ToString()
   at System.Net.Json.JsonUtility.EscapeString(String text)
   at System.Net.Json.JsonStringValue.WriteTo(TextWriter writer)
   at System.Net.Json.JsonCollection.WriteTo(TextWriter writer)
   at System.Net.Json.JsonObject.ToString()
   at System.Web.HttpWriter.Write(Object obj)
   at WebClient.Processor.FillResponse(HttpContext context, Object entity, OutputTypes outputType)
   at System.Dynamic.UpdateDelegates.UpdateAndExecuteVoid4[T0,T1,T2,T3](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at WebClient.Processor.ProcessRequest(HttpContext context)

編碼

JsonUtility.GenerateIndentedJsonText = true;
var jsonObject = new JsonObjectCollection();
context.Response.ContentType = JsonUtility.MimeType;
var jsonStringValue = new JsonStringValue("File", Convert.ToBase64String(binaryData, 0, binaryData.Length));
jsonObject.Add(jsonStringValue);
context.Response.Write(jsonObject);

有什么建議如何解決問題?

檢查IIS中應用程序池的內存限制和回收時間設置。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM