Previous | Index | Next 

[HOWTO] Determine if unsupported members throw an exception at runtime

Unsupported VB6 properties and methods – such as the DrawMode and ClipControls properties, the RichTextBox.SelPrint method, or the Toolbar.Change event – are marked as obsolete and can be scrutinized in Visual Studio’s Error List window. In addition, VB Migration Partner emits a remark that explains what happens if the property or method is invoked at runtime. In most cases, an unsupported property returns its default value and throws if a value other then the default value is assigned to it; similarly, an unsupported method throws an exception if it receives an argument that can’t be processed.

However, these runtime exceptions are turned off by default. This means that, for example, migrated .NET application behaves as if the DrawMode and ClipControls properties were never set, the RichTextBox.SelPrint method were never called, and the Toolbar.Change event were never raised. This arrangement enables the developer to test the migrated program without caring for such unsupported members.

In most cases, especially in the early stages of the migration process, this default behavior is OK. When you eventually have a working VB.NET or C# application, you might want to ensure that all minor details have been accounted for. To do so, you change the default behavior by adding the following statement in the .NET application:

        ' VB.NET 
        VB6Config.ThrowOnUnsupportedMembers = True

        // C# 
        VB6Config.ThrowOnUnsupportedMembers = True;

When the VB6Config.ThrowOnUnsupportedMembers property is set to True, calling an unsupported method or setting a property to an unsupported value throws an exception. Instead of modifying the migrated VB.NET code, you can set this option automatically by adding an appropriate InsertStatement pragma in the original VB6 code:

        Sub Main()
           
         '##InsertStatement VB6Config.ThrowOnUnsupportedMembers = True
         ' ...
        End Sub

 

Previous | Index | Next