Windows Forms Application Crashes When Calling ToolTip.SetToolTip Method for Associated TreeView control
| Article ID | : | 953102 |
| Last Review | : | May 13, 2008 |
| Revision | : | 1.1 |
RAPID PUBLISHING
Action
Result
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 System.ComponentModel.Component.Dispose()
  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.
Cause
Resolution
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.
More Information
STEPS TO REPRODUCE
====================
1. Using Visual Studio 2005 or Visual Studio 2008, create a new C# Windows Forms application.
2. Add a TreeView control to the form named treeView1.
3. Set the TreeView control’s ShowNodeToolTips property to True.
4. Add a ToolTip control to the form named toolTip1.
5. Add the following code to the form’s Load event handler:
 private void Form1_Load(object sender, EventArgs e)
       {
           for (int i = 0; i < 10; i++)
           {
               TreeNode newNode = new TreeNode();
               newNode.Text = test node + i.ToString();
               newNode.Tag = i.ToString();
               treeView1.Nodes.Add(newNode);
           }
       }
6. Add the following code to the MouseMove event handler of the TreeView control:
 private void treeView1_MouseMove(object sender, MouseEventArgs e)
       {
           TreeView tv = sender as TreeView;
           if (tv != null)
           {
               TreeNode tn = tv.GetNodeAt(new Point(e.X, e.Y));
               if (tn != null)
               {
                   this.toolTip1.SetToolTip(tv, tn.Text);
               }
           }
       }
7. Build the application and run it.
8. Hover the mouse over several nodes in the TreeView control.
9. Close the form to exit the application.
You should receive one of the errors listed in the Result section above.
When running the application under a native code debugger, you may also see an Access Violation occurring in the following call stack.
mscorlib_ni!System.Runtime.InteropServices.Marshal.PtrToStructure(IntPtr, System.Type)+0x5d
System.Windows.Forms.UnsafeNativeMethods.PtrToStructure(IntPtr, System.Type)+0×25
System_Windows_Forms_ni!System.Windows.Forms.TreeView.WmNeedText(System.Windows.Forms.Message ByRef)+0×35
System_Windows_Forms_ni!System.Windows.Forms.TreeView.WndProc(System.Windows.Forms.Message ByRef)+0x36e281
System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)+0xd
System_Windows_Forms_ni!System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)+0×36
System_Windows_Forms_ni!System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)+0x5a
user32!InternalCallWinProc+0×23
user32!UserCallWinProcCheckWow+0x14b
user32!CallWindowProcAorW+0×97
user32!CallWindowProcW+0x1b
comctl32!CallOriginalWndProc+0x1a
comctl32!CallNextSubclassProc+0x3c
comctl32!DefSubclassProc+0×46
comctl32!TTSubclassProc+0×59
comctl32!CallNextSubclassProc+0x3c
DISCLAIMER
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, MICROSOFT AND/OR ITS SUPPLIERS DISCLAIM AND EXCLUDE ALL REPRESENTATIONS, WARRANTIES, AND CONDITIONS WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT LIMITED TO REPRESENTATIONS, WARRANTIES, OR CONDITIONS OF TITLE, NON INFRINGEMENT, SATISFACTORY CONDITION OR QUALITY, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, WITH RESPECT TO THE MATERIALS.
Keywords:Â |
kbnomt kbrapidpub KB953102 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
Microsoft Corporation. All rights reserved. Terms of Use | Trademarks
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Back to the top
Leave a Reply