I have a WinForms application (x64) running under .Net 4.6.
I'm using XslCompiledTransform in order to manipulate some XML files using XSLT files.
The XSLT transformation is done in parallel for many XML files as follow:
Parallel.ForEach(totalBusWorkingFolderFileItem, po, (xsltPath, loopState) =>
{
XmlTextWriter transformedXml = new XmlTextWriter(stringWriter);
// Create a XslCompiledTransform to perform transformation
XslCompiledTransform xsltTransform = new XslCompiledTransform();
XsltSettings settings = new XsltSettings()
{
EnableDocumentFunction = true,
EnableScript = true
};
lock (xsltCompilerLocker)
{
xsltTransform.Load(xsltPath, settings, new XmlUrlResolver());
}
xsltTransform.Transform(xmlReader, argsList, transformedXml);
... (Do something with transformedXml)
}
As I understood from MSDN, the Load method creates temporary files under the %TEMP% folder (In case of script enabled on the XslCompiledTransform object) these files are getting deleted once the call to the Load method is done.
My problem is that I got the following exception even when locking the Load method:
Access to the path 'C:\Users\erezk\AppData\Local\Temp\iapqiwqu.tmp' is denied.
This file is one of the temporary file the Load call is generated.
Does anyone encountered this before?
The
XslCompiledTransformclass has a property calledTemporaryFiles. This will contain the filenames of the temporary files that were created during a successfulLoadcall. The documentation of this property (https://msdn.microsoft.com/de-de/library/system.xml.xsl.xslcompiledtransform.temporaryfiles(v=vs.110).aspx) says that the user can delete them after the call toLoad. So I don't think they are deleted automatically. Hence this property wouldn't make sense otherwise.So maybe you should try to delete them by yourself inside the lock-block.