并msxsl内存泄漏的bug修复.NET 2或.NET 4?内存、msxsl、NET、bug

2023-09-05 04:37:04 作者:卫生巾才是吸血鬼@

我的工作,涉及到XSLT的项目。并希望在我的XSLT使用C#脚本。 就像在下面的链接。 XSLT 1.0获取当前日期时间

I'm working on a project that involves XSLT. And would like to use a C# script in my XSLT. Just like in the following link. XSLT 1.0 Get Current DateTime

虽然我遇到了这个知识库文章 http://support.microsoft.com/kb/316775说这个加载样式表多次时,会导致内存泄漏。

Although I ran into this KB article http://support.microsoft.com/kb/316775 saying that this causes memory leaks when loading the stylesheet multiple times.

的知识库文章并没有说哪个.NET版本是否受到影响。谁能告知这是否固定在.NET 2.0或更高版本?

The KB article doesn't say which .NET versions are affected. Can anyone advise whether this is fixed in .NET 2.0 or higher ?

我的目标环境有.NET 2.0和3.5,虽然code没有XSLT转换被编译到.NET 2.0。

My target environment have .NET 2.0 and 3.5, although the code that does the XSLT transform is compiled to .NET 2.0.

注:我没有在code的运行转换控制。我可以只写XSLT 的

推荐答案

这是不是一个错误 - 在首位

This isn't a bug -- in the first place.

更重要的是,这绝对是可以避免的。

More importantly, this is absolutely avoidable.

解决的办法是:没有的有内嵌脚本,但使用包含有用的扩展功能的扩展对象

The solution is: not to have inline scripts but to use an extension objects that contains the wanted extension functions.

更多信息如何编写扩展函数作为扩展对象的一部分 - 为XslCompiledTransform可以在这里找到:

More information how to write extension functions as part of an extension object -- for XslCompiledTransform can be found here:

http://msdn.microsoft.com/en-us/library/tf741884

和全code在这里例如:

and a full code example here:

的http://msdn.microsoft.com/en-us/library/system.xml.xsl.xsltargumentlist.addextensionobject