FIX: XML Input File Erased When You Use Transform Method of XslTranform Object (318143)



The information in this article applies to:

  • Microsoft Windows .NET Framework Class Libraries 1.1
  • Microsoft XML Classes (included with the .NET Framework 1.0)

This article was previously published under Q318143

SYMPTOMS

This bug was corrected in P1. When you use the Transform method of the XslTransform object, you may receive the following System.IO.IOException error message, and the original input file is empty:
An unhandled exception of type 'System.IO.IOException' occurred in system.xml.dll
The process cannot access the file "filename" because it is being used by another process.

CAUSE

The input XML file name and output file name are the same.

RESOLUTION

To resolve this problem, make sure that the input file name and the output file name are different.

STATUS

This bug was corrected in Microsoft .NET Framework 1.1.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Use Microsoft Notepad to create a new XML document that contains the following code, and then save the document as Library.xml in the root folder of your hard disk:
    <library>
      <book genre='novel' ISBN='1-861001-57-5'>
         <title>Pride And Prejudice</title>
      </book>
      <book genre='novel' ISBN='1-81920-21-2'>
         <title>Hook</title>
      </book>
    </library>
    					
  2. Use Notepad to create a new XML document that contains the following code, and then save the document as Msg.xsl in the root folder of your hard disk:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
      <xsl:template match="/">
         <h1>Root node is  <xsl:value-of select="local-name(//*[position() = 1])" /></h1> 
      </xsl:template>
    </xsl:stylesheet>
    					
  3. In Microsoft Visual Basic .NET, create a new Console Application project, and then replace the code in Module1.vb with the following code:
    Imports System.Xml.Xsl
    
    Module Module1
    
        Sub Main()
            Dim objXsl As XslTransform
            objXsl = New XslTransform()
            objXsl.Load("c:\msg.xsl")
            objXsl.Transform("c:\library.xml", "c:\library.xml")
        End Sub
    
    End Module
    					
  4. Run the project. Note that you receive an error message, and the input file is erased. To resolve the problem, change the line that performs the Transform method, as follows:
    objXsl.Transform("c:\library.xml", "c:\library1.xml")
    					

Modification Type:MinorLast Reviewed:4/28/2003
Keywords:kbbug kbpending KB318143