Menu

#13 form.Hide() and form.Dispose() called out of order

open
nobody
None
5
2006-07-27
2006-07-27
Anonymous
No

In the .NET 2.0 Alpha 5 release NUnitFormTest.Verify()
includes the following section of code:

<<
foreach (Form form in allForms)
{
if (!KeepAlive(form))
{
form.Hide();
form.Dispose();
} //else branch not tested
}
>>

This results in the following exception when invoked:

<<
TearDown : System.Reflection.TargetInvocationException
: Exception has been thrown by the target of an invocation.
----> System.ObjectDisposedException : Cannot access
a disposed object.
>>

Simply reversing the order of form.Hide() and
form.Dispose() appears to fix the issue.

Discussion

  • Ashley Tate

    Ashley Tate - 2006-07-27

    Logged In: YES
    user_id=1320398

    I added this bug - forgot to login first.

     
  • Adam Vandenberg

    Adam Vandenberg - 2007-01-13

    Logged In: YES
    user_id=1636255
    Originator: NO

    I wonder if replacing both of these lines with "form.Close()" would be a better approach.

     

Log in to post a comment.