VB Migration Partner

KNOWLEDGE BASE - Language


Previous | Index | Next 

[PRB] The VB.NET application doesn’t compile because of a “Method XYZ not found” compilation error

Note: this article only applies to conversions to VB.NET.

If a VB6 class has a method with a Friend scope and the class is implemented as an interface, the following compilation error can appear after the conversion to VB.NET:

        Method 'XYZ' not found

For example, consider a VB6 class named Rectangle:

        ' (inside the Rectangle class)
        Friend Sub Init(ByVal width As Single, ByVal height As Single)
            ' store width/height in member variables
        End Sub
        ' ... more class members here...

Let’s further assume that the VB6 application includes a Square class defined as follows:

        ' (inside the Square class)
        Implements Rectangle
        ' ... class members here...

The Implements Rectangle statement forces VB Migration Partner to render Rectangle as an interface and to rename the original Rectangle class as RectangleClass:

        ' (VB.NET code)
        Public Class RectangleClass
            Implements Rectangle

            Friend Sub Init(width As Single, height As Single)
                ' store width/height in member variables
            End Sub
            ' ... add more class members here...
        End Class

Finally, assume that elsewhere in the VB6 project you have the following method:

        Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
            Set GetRectangle = New Rectangle
            GetRectangle.Init width, height
        End Function

Here’s how VB Migration Partner translates the GetRectangle method to VB.NET:

        Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
            GetRectangle = New RectangleClass()
            GetRectangle.Init(width, height)
        End Function

Here’s the problem: the GetRectangle local variable contains a pointer to the Rectangle interface, not to the RectangleClass concrete class. The Init method has a Friend scope and isn’t part of the Rectangle interface, therefore it can’t be reached through the reference in the GetRectangle variable. You can solve this problem by slightly tweaking the VB6 code, as follows:

        Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
            Dim rect As New Rectangle
            rect.Init width, height
            Set GetRectangle = rect
        End Function

which translates to the following VB.NET code:

        Function GetRectangle(ByVal width As Single, ByVal height As Single) As Rectangle
            Dim rect As New RectangleClass()
            rect.Init(width, height)
            Return rect
        End Function

This code compiles and runs correctly.

Previous | Index | Next 




Follow Francesco Balena on VB6 migration’s group on

LinkedIn





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.

newsletter



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