Microsoft KB Archive/907963

= You cannot access fields for types that are defined in a partial class when you use the Visual Basic Code Model to extend Visual Studio 2005 =

Article ID: 907963

Article Last Modified on 3/14/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Team System Architect Edition
 * Microsoft Visual Studio 2005 Team System Developer Edition
 * Microsoft Visual Studio 2005 Team System Test Edition
 * Microsoft Visual Studio 2005 Team Foundation

-





SYMPTOMS
When you use the Visual Basic Code Model to extend Microsoft Visual Studio 2005, you cannot access fields for types that are defined in a partial class. This problem occurs when you use the CodeType member of the CodeTypeRef interface.



CAUSE
This problem occurs because the CodeType member is set to null when the definition that the CodeType member references is not defined in the first segment of a partial class that the Code Model parses.



RESOLUTION
To resolve this problem, use one of the following methods:  Put the second segment of the partial class in a source file that has a name that appears alphabetically before the source file that contains the first declaration of the partial class.  Move the definition that the CodeType member references to the first segment of the partial class. Use this method when multiple segments of a partial class appear in the same file. The following code sample shows how to do this. Partial Friend Class SomeDataSet Friend Class SomeTableRow

End Class

End Class

Partial Friend Class SomeDataSet

End Class 



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



Steps to reproduce the problem
 Create a Visual Basic Class Library.  Add code that is similar to the following code sample to the Class1.vb file. Partial Friend Class SomeDataSet

End Class

Partial Friend Class SomeDataSet

Friend Class SomeTableRow

End Class

End Class

Public Class SomeObject

Friend Sub Sub1

End Sub

Private mDataRow As SomeDataSet.SomeTableRow

End Class </li> On the Tools menu, point to Macros, and then click Macros IDE. The Macros IDE appears.</li> On the View menu of the Macros IDE, click Project Explorer.</li> In Project Explorer, expand MyMacros.</li> Double-click Module1.</li>  Add the following code sample to the module file. Sub Macro1 Dim cv As CodeVariable = DTE.ActiveDocument.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementVariable) MsgBox(cv.Type.CodeType.FullName) End Sub </li> Close the Macros IDE.</li> In the Visual Basic Class Library, put the insertion point on mDataRow.</li> On the Tools menu in the Visual Studio IDE, point to Macros, and then click Macro Explorer. Macro Explorer appears.</li> In Macro Explorer, expand MyMacros, and then expand Module1.</li> In Macro Explorer, right-click Macro1, and then click Run.</li></ol>

For more information about the CodeType member, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/0c5t3tay(en-US,VS.80).aspx

For more information about Microsoft Visual Studio Team System, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/teamsystem/default.aspx

For more information about unit testing, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/ms364064(vs.80).aspx

Keywords: kbbug kbtshoot kbprb KB907963

-

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

© Microsoft Corporation. All rights reserved.