Microsoft KB Archive/316180

= FIX: System.NullReferenceException error occurs if you assign a TreeView node tag property =

Article ID: 316180

Article Last Modified on 1/20/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition

-



This article was previously published under Q316180



SYMPTOMS
If you assign a value to a property of an ActiveX control in Visual Basic .NET, you may receive the following error message when you run your application:

An unhandled exception of type 'System.NullReferenceException' occurred in .exe

Additional information: Object reference not set to an instance of an object.

Note The example that is used to reproduce this error message uses the ActiveX version of the TreeView control. This error message may occur with other controls.



CAUSE
The problem can occur because the Set method of the control expects a Reference type instead of a Value type, which results in the NullReferenceException. Visual Basic .NET always calls the Set method of a property if it is available. If you want to call the Let method, you need to specify the Let method explicitly.



RESOLUTION
Use one of the following methods to resolve this problem:  Use the Visual Basic .NET version of the control. -or-

  Explicitly tell the compiler to use the Let method. The following code demonstrates the syntax to use: AxTreeView1.Nodes.Add(,, , &quot;Node 1&quot;) AxTreeView1.Nodes(1).let_Tag(&quot;MyTag&quot;) 



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

This bug was corrected in Visual Studio .NET 2003.



Steps to Reproduce the Behavior
 Create a new Windows Application in Visual Basic .NET. Customize the toolbox to add the Treeview control (MSComctl.ocx). The legacy TreeView control appears as TreeCtrl in the toolbox.</li> Add an instance of TreeCtrl to Form1.</li>  Add the following code to the Load event of Form1: AxTreeView1.Nodes.Add(,, , &quot;Node 1&quot;) AxTreeView1.Nodes(1).Tag = &quot;MyTag&quot; </li> Build and run the project. You should receive the error message that is listed in the &quot;Symptoms&quot; section.</li></ol>

Keywords: kberrmsg kbbug kbfix kbpending kbvs2002sp1sweep kbvs2005swept kbvs2005doesnotapply KB316180

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.