System Namespace
The exception that is thrown when an operation is performed on a disposed object.
[ Visual Basic, C# ] The following example demonstrates an error that causes the ObjectDisposedException exception to be thrown.
[ VB ]
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
Response.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 )
{
Response.WriteLine ( "Caught: {0}", e.Message );
}
}
}
[ Visual Basic, C# ] This code produces the following output:
[ Visual Basic, C# ] Caught:
Cannot access a closed Stream.
IDisposable