Microsoft KB Archive/892544

= FIX: You receive exception error messages when you use the StreamWriter.Flush method or the StreamWriter.Close  method to access a file on a disk that has insufficient space in .NET Framework 1.1 =

Article ID: 892544

Article Last Modified on 12/3/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1 Service Pack 1
 * Microsoft .NET Framework 1.1

-





SYMPTOMS
On a computer that is running Microsoft .NET Framework 1.1, when you use the StreamWriter.Flush method or the StreamWriter.Close method to access a file on a disk that has insufficient space, you receive the following exception error message:

System.IO.IOException: There is not enough space on the disk.

After you free up space on the disk and then try to access the file again, you receive the following exception error message:

System.IO.IOException: The process cannot access the file &quot;C:\outputTest.txt&quot; because it is being used by another process.



CAUSE
This problem occurs if the common language runtime (CLR) does not close the file handle after you receive the first exception error message. If the file handle does not close, you cannot access the file regardless of how much space is on the disk.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next Service Pack that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The English version of this hotfix has the file attributes (or later file attributes) that are listed in the following table. The dates and times for these files are listed in Coordinated Universal Time (UTC). When you view the file information, it is converted to local time. To find the difference between UTC and local time, use the Time Zone tab in the Date and Time tool in Control Panel.   Date         Time   Version        Size       File name --  24-Feb-2005  11:50  1.1.4322.2064  2,138,112  Mscorlib.dll 24-Feb-2005 11:50                    10,912  Mscorlib.ldo 25-Feb-2005 03:50  1.1.4322.2064  2,519,040  Mscorsvr.dll 25-Feb-2005 03:51  1.1.4322.2064  2,506,752  Mscorwks.dll



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
 Start Microsoft Visual Studio .NET 2003. On the Start Page menu, click New Project. In the New Project window, click Visual C# Project, click Windows Application, and then click OK. In Solution Explorer, right-click Form1.cs, and then click View Code.  Replace the code in Form1.cs with the following code: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.IO; using System.Text;

namespace WindowsApplication1 {   public class Form1 : System.Windows.Forms.Form {       private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null;

public Form1 {           InitializeComponent; }

protected override void Dispose( bool disposing ) {           if( disposing ) {               if (components != null) {                   components.Dispose; }           }            base.Dispose( disposing ); }

#region Windows Form Designer generated code

private void InitializeComponent {           this.button1 = new System.Windows.Forms.Button; this.SuspendLayout;

this.button1.Location = new System.Drawing.Point(120, 88); this.button1.Name = &quot;button1&quot;; this.button1.TabIndex = 0; this.button1.Text = &quot;Test&quot;; this.button1.Click += new System.EventHandler(this.button1_Click);

this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.Add(this.button1); this.Name = &quot;Form1&quot;; this.Text = &quot;Form1&quot;; this.ResumeLayout(false);

}       #endregion

[STAThread] static void Main {           Application.Run(new Form1); }

private void button1_Click(object sender, System.EventArgs e)       { System.IO.TextWriter _textWriter; try {               //initializing textWriter _textWriter = new StreamWriter( @&quot;Drive:\outputTest.txt&quot;,true,Encoding.Default ); }           catch( Exception exInit ) {               MessageBox.Show(exInit.ToString); return; }

string str = new String( 'a', 100 );

try {

for( int i=0; i<100; i++ ) {                   _textWriter.WriteLine( &quot;{0}:{1}&quot;, i, str ); _textWriter.Flush; }               MessageBox.Show( &quot;file created&quot; ); }           catch( Exception ex ) {               MessageBox.Show(ex.ToString); return; }           finally {               try {                   // closing file object _textWriter.Close; }               catch( Exception ex ) {                   MessageBox.Show(ex.ToString); }               finally {                   _textWriter = null; }

}       }    } }  Note The placeholder   is a placeholder for the disk that has insufficient space. </li> Press CTRL+F5 to run the application that you created in step 2.</li> Click Test. You will receive the following exception error message two times:

System.IO.IOException: There is not enough space on the disk.

</li> Run the Disk Cleanup wizard (Cleanmgr.exe) to free hard disk space.</li> Click Test again. You will receive the following exception error message:

System.IO.IOException: The process cannot access the file &quot; :\outputTest.txt&quot; because it is being used by another process.

</li></ol>

Additional query words: framework filehandle

Keywords: kbqfe kbhotfixserver kberrmsg kbprogramming kbvs kbwindowsforms kbfix KB892544

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.