The exception that is thrown when an operation is performed on a disposed object.
For a list of all members of this type, see ObjectDisposedException Members.
System.Object
System.Exception
System.SystemException
System.InvalidOperationException
System.ObjectDisposedException
[Visual Basic] <Serializable> Public Class ObjectDisposedException Inherits InvalidOperationException [C#] [Serializable] public class ObjectDisposedException : InvalidOperationException [C++] [Serializable] public __gc class ObjectDisposedException : public InvalidOperationException [JScript] public Serializable class ObjectDisposedException extends InvalidOperationException
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
[Visual Basic, C#, C++] The following example demonstrates an error that causes the ObjectDisposedException exception to be thrown.
[Visual Basic] Imports System Imports System.IO Public Class ObjectDisposedExceptionTest Public Shared Sub Main() Dim ms As New MemoryStream(16) ms.Close() Try ms.ReadByte() Catch e As ObjectDisposedException Console.WriteLine("Caught: {0}", e.Message) End Try End Sub 'Main End Class 'ObjectDisposedExceptionTest [C#] 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); } } } [C++] #using <mscorlib.dll> using namespace System; using namespace System::IO; void main() { MemoryStream* ms = new MemoryStream(16); ms->Close(); try { ms->ReadByte(); } catch (ObjectDisposedException* e) { Console::WriteLine(S"Caught: {0}", e->Message); } }
[Visual Basic, C#, C++] This code produces the following output:
[Visual Basic, C#, C++] Caught:
Cannot access a closed Stream.
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
Assembly: Mscorlib (in Mscorlib.dll)
ObjectDisposedException Members | System Namespace | IDisposable