Udostępnij za pośrednictwem


Method '<methodname>' does not have a signature compatible with delegate <'delegatename'>

This error occurs when a conversion is required between a method and a delegate that is not possible. The cause of the error can be conversion between parameters or, when the method and delegate are functions, conversion in the return values.

The following code illustrates failed conversions. The delegate is FunDel.

Delegate Function FunDel(ByVal i As Integer, ByVal d As Double) As Integer

The following functions each differ from FunDel in a way that will cause this error.

Function ExampleMethod1(ByVal m As Integer, ByVal aDate As Date) As Integer
End Function

Function ExampleMethod2(ByVal m As Integer, ByVal aDouble As Double) As Date
End Function

Each of the following assignment statements causes the error.

Sub Main()
    ' The second parameters of FunDel and ExampleMethod1, Double and Date,
    ' are not compatible.
    'Dim d1 As FunDel = AddressOf ExampleMethod1

    ' The return types of FunDel and ExampleMethod2, Integer and Date,
    ' are not compatible.
    'Dim d2 As FunDel = AddressOf ExampleMethod2

End Sub

Error ID: BC31143

To correct this error

  • Examine the corresponding parameters and, if they are present, return types to determine which pair is not compatible.

See Also

Concepts

Relaxed Delegate Conversion

Delegates and the AddressOf Operator