BUG: UML code generator places IMPORTS inside namespace declarations (317578)



The information in this article applies to:

  • Microsoft Visio for Enterprise Architects (2002)
  • Microsoft Visual Basic .NET (2002)

This article was previously published under Q317578

SYMPTOMS

When you use the Unified Modeling Language (UML) software diagram template that is included with Visio 2002 to generate Visual Basic .NET (VB.NET) code, you may receive the following compile error message when a class imports a class from another namespace:
"Imports statement must precede any declaration"

CAUSE

The code generator places the VB.NET IMPORTS statement inside the namespace declaration. The VB.NET language specification requires that you place the IMPORTS statement outside the namespace declaration.

NOTE: This behavior does not occur when you use C# to generate code. Although Microsoft Visio for Enterprise Architects (VEA) generates the C# USING command inside the namespace declaration, the C# language specification permits this construction.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This bug was corrected in Visual Studio .NET 2003.

MORE INFORMATION

Steps to Reproduce Behavior

To receive the error message, follow these steps:
  1. Open Microsoft Visio.
  2. In Category, on the left, click Software.
  3. Follow these steps to create a package:
    1. Select the UML Model Diagram template.
    2. In the Model Explorer on the left, right-click Top Package, point to New, and then click Package.
    3. Click OK to create a package named Package1.
  4. Follow the previous steps to create another package named Package2.
  5. Right-click Package1, point to New, and then click Class to create a class named Class1.
  6. Right-click Package2, point to New, and then click Class to create a class named Class2.
  7. Double-click Class1, click the Attributes category, create an attribute named Size, and then click Package2:Class2 on the Type drop-down list.
  8. To generate the solution, follow these steps:
    1. On the main menu in the Visio environment, click UML, click Code, and then click Generate.
    2. In the Generate dialog box, select Visual Basic as the target language, and then click to select all of the items on the right. The default location is C:\Documents and Settings\YourComputerName\My Documents\.
    3. Click Add classes to Visual Studio Project, and then click Class Library Template. Name the solution MySolution.sln. Click OK to close the dialog box.
  9. In the UML Code Generation dialog box, click OK to create a directory.
  10. Open MySolution.sln from the MyDocuments directory.
  11. Build the solution.

Modification Type:MinorLast Reviewed:1/25/2006
Keywords:kbvs2005doesnotapply kbvs2005swept kbtshoot kberrmsg kbvs2002sp1sweep kbbug kbpending KB317578 kbAudDeveloper