全部,C#XSLT轉換內存不足
我使用XSLT轉換XML文檔的代碼如下。 問題是當XML文檔大約12MB時,C#內存不足。 有沒有消耗那麼多內存做不同的方式做轉換?
public string Transform(XPathDocument myXPathDoc, XslCompiledTransform myXslTrans)
{
try
{
var stm = new MemoryStream();
myXslTrans.Transform(myXPathDoc, null, stm);
var sr = new StreamReader(stm);
return sr.ReadToEnd();
}
catch (Exception e)
{
//Log the Exception
}
}
這裏是堆棧跟蹤:
at System.String.GetStringForStringBuilder(String value, Int32 startIndex, Int32 length, Int32 capacity)
at System.Text.StringBuilder.GetNewString(String currentString, Int32 requiredLength)
at System.Text.StringBuilder.Append(Char[] value, Int32 startIndex, Int32 charCount)
at System.IO.StreamReader.ReadToEnd()
at Transform(XPathDocument myXPathDoc, XslCompiledTransform myXslTrans)
您能否提供完整的異常詳細信息,即catch塊中的e.ToString()的輸出?你還可以展示你的變換和(縮小的)樣本輸入文檔嗎? – 2010-09-23 10:20:59
還有其他的東西:當它與10MB輸入一起工作時,產生的字符串有多大? – 2010-09-23 11:05:46
它可能是你有一個xslt導致大量輸出的問題,你有沒有嘗試運行在Visual Studio中的xml或其他工具之外的代碼提供的上下文中的轉換? – TheCodeKing 2010-09-23 14:56:10