See Also: ObjectDisposedException Members
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.