VB Migration Partner

KNOWLEDGE BASE - Classes and COM objects

Previous | Index | Next 

[HOWTO] Get rid of the "Class" suffix used for COM classes

When converting a type library for use with a .NET client the TlbImp.exe tool (used by VB Migration Partner behind the scenes) creates both an interface type (e.g. ADODB.Recordset) and a creatable class whose name has a “Class” suffix (e.g. ADODB.RecordsetClass). When migrating the VB6 client application to VB.NET, VB Migration Partner preserves this distinction and uses the interface name in plain Dim statement and the creatable class name in As New clauses, for example:

        Dim rs As ADODB.Recordset
        Dim rs2 As New ADODB.RecordsetClass

There are a number of reasons for following this approach. For example, consider the following VB6 code:

        '## AutoNew True
        Dim rs As New ADODB.Recordset

        Sub Test()
            If rs.Connection Is Nothing Then Exit Sub
        End Sub

VB Migration Partner correctly translate the above code snippet to VB.NET as follows:

        Dim rs As ADODB.RecordsetClass

        Sub Test()
            If AutoNew6(rs).Connection Is Nothing Then Exit Sub
        End Sub

Notice that the AutoNew6 helper method ensures that a new ADODB.Recordset object is istantiated if and only if the rs variable is Nothing when it is referenced. However, for the AutoNew6 method to work correctly, the type of the variable passed to it must match a creatable class, hence the variable is declared of type ADODB.RecordsetClass. If you drop the “Class” suffix, the VB.NET compiler complains with the following error message:

    Type argument 'ADODB.Recordset' must have a public parameterless instance constructor 
    to satisfy the 'New' constraint for type parameter 'T'.

While the “Class” suffix hampers neither code readability nor performance, a few developers might want to get rid of it. VB Migration Partner doesn’t currently offer a pragma to suppress the Class suffix, however you can usually achieve this goal by means of one or more project-level PostProcess pragmas. For example, this pragma gets rid of the “Class” suffix for all the objects in the ADODB and RDO libraries:

        '## project:PostProcess "\b(?<type>As\s+(New\s+)?(ADODB|RDO)\.\w+)Class\b",
            "${type}", True
Previous | Index | Next 

Follow Francesco Balena on VB6 migration’s group on


Read Microsoft Corp’s official case study of a VB6 conversion using VB Migration Partner.

Code Architects and its partners offers remote and onsite migration services.

More details

Subscribe to our free newsletter for useful VB6 migration tips and techniques.


To learn more about your VB6 applications, run VB6 Analyzer on your source code and send us the generated text file. You will receive a detailed report about your VB6 applications and how VB Migration Partner can help you to quickly and effectively migrate it to .NET.

Get free advice

A fully-working, time-limited Trial Edition of VB Migration Partner allows you to test it against your actual code

Get the Trial

The price of VB Migration Partner depends on the size of the VB6 application, the type of license, and other factors

Request a quote

Migrating a VB6 application in 10 easy steps

Comparing VB Migration Partner with Upgrade Wizard

Migration tools: Feature Comparison Table

All whitepapers