Previous | Index | Next 

[PRB] The migrated VB.NET application can’t compile because of the error “ ‘XYZ’ is already declared in this enum”

VB6 is more forgiving than VB.NET in how names can be assigned to items in an Enum block. For example, the following code is valid under VB6:

        Public Enum TestEnum
            [Sub]      ' names can be equal to reserved keywords
            [16 bit]   ' names can contain spaces
            [2D]       ' names can start with a digit
            [Three-D]  ' names can contain invalid characters
        End Enum

VB.NET accepts enum items whose name matches a language keyword (if the name is enclosed between square brackets), but rejects with a compilation error any attempt to use spaces or other invalid characters, as well as names that start with a digit. 

VB Migration Partner follows the following strategy when converting enum items: it renders spaces and invalid characters as underscores and prefixes the name with another underscore if the name starts with a digit. As in VB6, if the name matches a language keyword, the name is enclosed between square brackets. 

This conversion strategy works in nearly all cases, but you should be aware that there is a small chance that it generates two or more enum elements with same name. For example, the following VB6 Enum block:

        Public Enum TestEnum
        End Enum

produces three Enum elements with same name, which in turn produces two instances of the following error message:

        '_16bit_' is already declared in this enum

The obvious fix for this problem is renaming one or more enum items in the original VB6 code so that no duplicate names are created during the migration process.


Previous | Index | Next