BCL mscorlib [00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ] 1.0.5000.0 2.0.0.0 4.0.0.0 All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe. System.InvalidOperationException System.Runtime.InteropServices.ComVisible(true)

For additional information about disposing objects, see the interface.

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

`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.

The exception that is thrown when an operation is performed on a disposed object.

- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The following example displays the error message of a instance created using this constructor.

  using System;

  public class ExampleDisposableObject : IDisposable { public static void Main() {

  ExampleDisposableObject obj = new ExampleDisposableObject();

  obj.Close();

  try { Console.WriteLine(obj); } catch (ObjectDisposedException e) { Console.WriteLine("Caught: {0}", e.Message); } }

  public ExampleDisposableObject() { isDisposed = false; }

  ~ExampleDisposableObject() { Dispose(true); }

  public void Close() { Dispose(true); }

  public void Dispose() { Dispose(true); }

  public void Dispose(bool disposing) { isDisposed = true; }

  public override String ToString() { if(isDisposed) throw new ObjectDisposedException("ExampleDisposableObject"); else return "This is an instance of ExampleDisposableObject."; }

  private bool isDisposed; }

  The output is

  Caught: Cannot access a disposed object named "ExampleDisposableObject".

  Object name: "ExampleDisposableObject".

  The property is initialized to a system-supplied message that describes the error and includes the parameter. This message takes into account the current system culture.

  The InnerException property of the new instance is initialized to null.

  If is null, the Message property contains only an error message.

  Initializes a new instance of the class with a string containing the name of the disposed object.

  A string containing the name of the disposed object.
  0
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  To be added.

  Initializes a new instance of the class with serialized data.

  The that holds the serialized object data about the exception being thrown.
  The that contains contextual information about the source or destination.
- Constructor
  2.0.0.0
  4.0.0.0

  An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor.

  Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception.

  The error message that explains the reason for the exception.
  The exception that is the cause of the current exception. If is not null, the current exception is raised in a catch block that handles the inner exception.
- Constructor
  1.0.5000.0
  2.0.0.0
  4.0.0.0

  The following example throws a instance created using this constructor.

  using System;

  public class ExampleDisposableObject : IDisposable { public static void Main() {

  ExampleDisposableObject obj = new ExampleDisposableObject();

  obj.Close();

  try { Console.WriteLine(obj); } catch (ObjectDisposedException e) { Console.WriteLine("Caught: {0}", e.Message); } }

  public ExampleDisposableObject() { isDisposed = false; }

  ~ExampleDisposableObject() { Dispose(true); }

  public void Close() { Dispose(true); }

  public void Dispose() { Dispose(true); }

  public void Dispose(bool disposing) { isDisposed = true; }

  public override String ToString() { if(isDisposed) { string message = "Oh-oh! This object has been disposed!"; string objectName = "ExampleDisposableObject"; throw new ObjectDisposedException(objectName, message); } else return "Hello, World!"; }

  private bool isDisposed; }

  The output is

  Caught: Oh-oh! This object has been disposed!

  Object name: "ExampleDisposableObject".

  The error message that explains the reason for the exception.

  The InnerException property of the new instance is initialized to null.

  If is null, the Message property contains only an error message.

  Initializes a new instance of the class with the specified object name and message.

  The name of the disposed object.
  The error message that explains the reason for the exception.
  0
- Method
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.Void `` `` To be added.

  Retrieves the object with the parameter name and additional exception information.

  The that holds the serialized object data about the exception being thrown. The that contains contextual information about the source or destination.
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A that describes the error.

  If the property is not null, the message includes the name of the object.

  This property overrides .

  Gets the message that describes the error.

  0
- Property
  1.0.5000.0
  2.0.0.0
  4.0.0.0
  System.String

  A containing the name of the disposed object.

  If the current property is not null or , the value of this property is included in the string returned by the property.

  Gets the name of the disposed object.

  0
0