none
Calling Dispose() method on a XmlTextWriter (While writing file to a Low disk space) results in IO Exception. RRS feed

  • Question

  • Pre Requisites:

       1. Have a drive location with no free space(0 bytes).

       2. In the Try block , Create a Xml Text writer instance and start writing the file to the Drive location mentioned in Step1. a Zero Kb file is created for that Xml file.

       3. IO Exception is caught due to low disk space during writer creation and processing of exception is done during Catch block.

       4. In the Finally block , call XmlTextWriter.Dispose() method . It results in 1 more IO Exception with the inner message as Low disk space.

    Below is the code snippet.

     try
                {                
                    m_DigModWriter = new XmlTextWriter(m_ExportFileName, System.Text.Encoding.UTF8)
                {
                    Formatting = Formatting.Indented
                };                
                }
              
                catch (IOException ioException)
                {
                    command.CommandResult = CommonMethods.AddExceptionsToCommandResult("IOException", ioException, typeof(PASModbusSerializer));
                }
    
    
    
                finally
                {               
                    if (m_DigModWriter != null)
                    {
                        m_DigModWriter.Dispose();
                    }
                }
    How can we avoid the crash during such scenario? Is there alternative to tackle this issue?

    Please call +91-9008699779 or write to me if there are any more information required.

     


    Wednesday, May 13, 2015 1:51 PM

Answers

  • Hello Surendar Chikkarajan,

    >>How can we avoid the crash during such scenario? Is there alternative to tackle this issue?

    From your description, this scenario seems to be caused by the no free space(0 bytes) disk, I suggest you could first check if there is enough space by using DriveInfo Class(as cheong00 mentions in your another similar thread), if no enough space, then you decide to stop your application and tell the user that the diver is not enough.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 14, 2015 3:29 AM
    Moderator

All replies

  • Hello Surendar Chikkarajan,

    >>How can we avoid the crash during such scenario? Is there alternative to tackle this issue?

    From your description, this scenario seems to be caused by the no free space(0 bytes) disk, I suggest you could first check if there is enough space by using DriveInfo Class(as cheong00 mentions in your another similar thread), if no enough space, then you decide to stop your application and tell the user that the diver is not enough.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 14, 2015 3:29 AM
    Moderator
  • Thanks for the Reply Fred Bao !! I have one more question based on your reply. So Dispose() Method do need some free memory space in the drive during its invoke and will result in a crash if there is 0 kb space? If that is the case , What would be minimum disk space that is required for Writing XML file using XMLTextWriter class and Dispose() operations? I think We will use that size as a reference before writing a File in any Disk location .
    Wednesday, May 27, 2015 8:59 AM
  • Hello Surendar,

    >>So Dispose() Method do need some free memory space in the drive during its invoke and will result in a crash if there is 0 kb space?

    I am not sure about this since the Dispose method is an internal method. However, there should be some cost when calling this method.

    >>If that is the case , What would be minimum disk space that is required for Writing XML file using XMLTextWriter class and Dispose() operations? I think We will use that size as a reference before writing a File in any Disk location.

    I do not know why you have such a requirement, for me, I would avoid to do some stuff on a less space disk. Or if you really want to know a proper value, since I think it is not possible to know the exact needed bytes, you could do a test is to start run your app with the disk with 1MB space(just for example), if it still crashes, then increase the value, if not, decrease the value.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, May 28, 2015 5:23 AM
    Moderator