Mono Class Library: System Namespace

System.ObjectDisposedException Class

Represents the error that occurs when an operation is performed on a disposed object. [Edit]

See Also: ObjectDisposedException Members

System.Object
     System.Exception
          System.SystemException
               System.InvalidOperationException
                    System.ObjectDisposedException

[System.Runtime.InteropServices.ComVisible(true)]
public class ObjectDisposedException : InvalidOperationException

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Note: For additional information about disposing objects, see the IDisposable interface.
[Edit]

Example

The following example demonstrates an error that causes the ObjectDisposedException exception to be thrown.

C# Example
using System;
using System.IO;

public class ObjectDisposedExceptionTest {
   public static void Main() {     
      MemoryStream ms = new MemoryStream(16);
      ms.Close();
      try {
         ms.ReadByte();
      } 
      catch (ObjectDisposedException e) {
         Console.WriteLine("Caught: {0}", e.Message);
      }
   }
}

The output is

Caught: Cannot access a closed Stream.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0