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 "Applies to" section.
MORE INFORMATION
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
- On the Tools menu, point to Macros, and then click Macros IDE. The Macros IDE appears.
- On the View menu of the Macros IDE, click Project Explorer.
- In Project Explorer, expand MyMacros.
- Double-click Module1.
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
- Close the Macros IDE.
- In the Visual Basic Class Library, put the insertion point on mDataRow.
- On the Tools menu in the Visual Studio IDE, point to Macros, and then click Macro Explorer. Macro Explorer appears.
- In Macro Explorer, expand MyMacros, and then expand Module1.
- In Macro Explorer, right-click Macro1, and then click Run.
For more information about the CodeType member, visit the following Microsoft Developer Network (MSDN) Web site:
For more information about Microsoft Visual Studio Team System, visit the following MSDN Web site:
For more information about unit testing, visit the following MSDN Web site:
Keywords: kbbug kbtshoot kbprb KB907963