BUG: The XmlValidatingReader class does not close the stream when the XML document references a DTD that has errors (816221)
The information in this article applies to:
- Microsoft .NET Framework 1.0
- Microsoft Windows .NET Framework 1.1
- Microsoft .NET Framework Class Libraries 1.0
- Microsoft Windows .NET Framework Class Libraries 1.1
- Microsoft Visual C# .NET (2002)
- Microsoft Visual C# .NET (2003)
- Microsoft Visual Basic .NET (2002)
- Microsoft Visual Basic .NET (2003)
SYMPTOMSWhen you validate your XML document by using the XmlValidatingReader class with respect to an external document type definition (DTD),
and the DTD has an error, the stream that is opened by XmlValidatingReader to load the DTD is not closed. Therefore, when you try to open
the DTD with write permissions, you receive the following error
message: An unhandled exception of type
'System.IO.IOException' occurred in mscorlib.dll Additional information:
The process cannot access the file "DTDFileName" because it is being used by
another process. CAUSEWhen you use XmlValidatingReader to validate an XML document with respect to DTD, the .NET
Framework internally opens a stream to read the DTD. When the error occurs
while validating the XML document, the stream that is used to read the DTD is
not closed, and you receive the error message that is listed in the "Symptoms"
section.WORKAROUNDTo work around this problem, use the garbage collector
(GarbageCollector.exe) to reclaim the unused memory and to close the stream. To
do this, add the following code in the beginning of the method where the DTD is
being corrected. Visual C# .NET Code// This method call triggers the garbage collector
// to collect the unreferenced memory.
GC.Collect();
// Wait for the GC's Finalize thread to finish
// executing all queued Finalize methods.
GC.WaitForPendingFinalizers(); Visual Basic .NET Code' This method call triggers the garbage collector
' to collect the unreferenced memory.
GC.Collect()
' Wait for the GC's Finalize thread to finish
' executing all queued Finalize methods.
GC.WaitForPendingFinalizers() For more information about the code to add to the RemoveTheErrorInDTD method, see the "More Information" section. STATUS Microsoft
has confirmed that this is a problem in the Microsoft products that are listed
at the beginning of this article.
REFERENCESFor more information about XML, visit the following MSDN Web
sites: For more information about garbage collection, visit the following
MSDN Web site:
Modification Type: | Major | Last Reviewed: | 4/26/2006 |
---|
Keywords: | kbvs2002sp1sweep kbBug kberrmsg kbGarbageCollect kbXML kbValidation kbFileIO KB816221 kbAudDeveloper |
---|
|