Tooltip, .ShowDialog(), and .Dispose() on .NET 2.0 generate a NullReferenceException

E

Emmanuel_

Hi,

I have the following problem, most probably a bug:

I have a windows form that incorporates one Button control and one ToolTip
control.

On the form's Load event, I am setting the tooltip message of the button by
calling the SetTooltip() method.
On the button's Click event the form is disposed using the .Dispose()
method.

If the form is opened from another form using the .ShowDialog() method, if
the button is pressed I get a NullReferenceException.


Notes:
1. If the form is called using the .Show() method then the exception
does not occur.
2. If the SetTooltip() method is not called then the exception does not
occur.
3. If the .Close() method is used on the Click event, instead of the
Dispose(), and the .Dispose method is called imediatelly after the
..ShowDialog() method, the exception does not occur.
4. This problem did not occur on the .NET 1.1

Is this some kind of bug ?

Thanks
Emmanuel
 
K

Karen Kenworthy

<< Is this some kind of bug ? >>

Apparently so. There's a new KB article that discusses the subject:

-------------------
SYMPTOMS
You may receive an error message when you try to close a Microsoft Windows
Forms-based application. Consider the following scenario: . A Microsoft
Windows Forms-based application uses ToolTips.
. The application is running on the Microsoft .NET Framework 2.0.
In this scenario, you may receive the following error message when you try
to close the application:
System.NullReferenceException: Object reference not set to an instance of an
object.
--------------------

They advise overriding the form's Dispose method. The suggested code is in
this article:

http://support.microsoft.com/kb/918146/en-us

Or you can ask customer support for a revised copy of
System.windows.forms.dll.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top