'Extension' attribute can be applied only to 'Module', 'Sub', or 'Function' declarations

The only way to extend a data type in Visual Basic is to define an extension method inside a standard module. The extension method can be a Sub procedure or a Function procedure. All extension methods must be marked with the extension attribute, <Extension()>, from the System.Runtime.CompilerServices namespace. Optionally, a module that contains an extension method may be marked in the same way. No other use of the extension attribute is valid.

Error ID: BC36550

To correct this error

  • Remove the extension attribute.

  • Redesign your extension as a method, defined in an enclosing module.


The following example defines a Print method for the String data type.

Imports StringUtility  
Imports System.Runtime.CompilerServices  
Namespace StringUtility  
    Module StringExtensions  
        Public Sub Print (ByVal str As String)  
        End Sub  
    End Module  
End Namespace  

See Also

Attributes overview
Extension Methods
Module Statement