Windows Forms Application Crashes When Calling ToolTip.SetToolTip Method for Associated TreeView control
You have developed a Microsoft .NET Framework 2.0 Windows Forms application which contains a ToolTip control and a Treeview control. The application calls the ToolTip control’s SetToolTip method multiple times, for example, in the MouseMove event of the TreeView Control; and passes the Treeview control as the first parameter to the SetToolTip method.
When hovering the mouse over a Node in the TreeView control, the ToolTip may not display all the text specified in the SetToolTip method. When exiting the application, you may also receive the following error:
Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Environment.GetResourceFromDefault(String key)
at System.ObjectDisposedException..ctor(String objectName)
at System.Windows.Forms.Control.DestroyHandle()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.Form.Dispose(Boolean disposing)
at WindowsFormsApplication1.Form1.Dispose(Boolean disposing) in C:\Projects\WindowsFormsApplication1\WindowsFormsApplication1\Form1.Designer.cs:line 20
at ()
at System.Windows.Forms.Form.WmClose(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
If you are debugging the application in Visual Studio, you may receive the following MDA error when exiting instead of the System.AccessViolationException above.
FatalExecutionEngineError was detected
The runtime has encountered a fatal error. The address of the error was at <address>, on thread <thread>. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
reserlution:
You can use one of the following solutions to work around this problem.
1. Set the TreeView control's ShowNodeToolTips property to False. This is the easiest solution if the intent is to use the ToolTip control for displaying ToolTips instead of the TreeView control's built-in Node ToolTips (the ToolTip control has some additional features not exposed by the TreeView control's ToolTip implementation).
2. Alternatively, you can remove the call to the ToolTip control's SetToolTip method, and use the TreeView control's built-in ToolTips. To do this, you must make sure that the TreeView control's ShowNodeToolTips property is set to True, and that you have set each TreeNode's ToolTipText property to the desired value.