asp.net.ph

ObjectDisposedException Class

System Namespace


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

ObjectDisposedException Class Members

Collapse   Constructors

Visibility Constructor Parameters
public ObjectDisposedException ( String objectName )
public ObjectDisposedException ( String objectName , String message )
public ObjectDisposedException ( String message , Exception innerException )

Collapse   Properties

Visibility Name Value Type Accessibility
public Message String [ Get ]
public ObjectName String [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
public GetObjectData ( SerializationInfo info , StreamingContext context ) Void

Example

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

See Also

IDisposable Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph