Extension methods must declare at least one parameter

Extension methods must declare at least one parameter. The first parameter specifies which type to extend.

An extension method without parameters is not valid because the first parameter specifies which data type the method extends. The first parameter is bound to the instance of the data type that invokes the method.

Error ID: BC36552

To correct this error

  • Add a parameter of the type that your method extends.

Example

The first parameter in the following example indicates that the Print method extends the String data type.

<Extension()> _
Public Sub Print (ByVal str As String)
    Console.WriteLine(str)
End Sub

When the extension method is called as follows, parameter str in the method is bound to greeting, the instance of String that calls Print. The compiler will use greeting as the argument to extension method Print.

    Dim greeting As String = "Hello"
    greeting.Print()

See Also

Concepts

Extension Methods (Visual Basic)

Procedure Parameters and Arguments

Procedures in Visual Basic