'System.Runtime.InteropServices.DllImportAttribute' cannot be applied to instance methods

A nonshared procedure is declared with the DllImportAttribute.

The common language runtime (CLR) recognizes this attribute and its EntryPoint property as designating a replacement procedure defined in an unmanaged dynamic-link library (DLL) outside the .NET Framework. When code calls the procedure to which the DllImportAttribute is applied, the common language runtime calls the designated unmanaged procedure instead.

Because unmanaged platforms outside the .NET Framework do not support nonshared procedures the same way the .NET Framework does, you cannot interoperate with them using nonshared procedures.

Error ID: BC31529

To correct this error

  • If the procedure does not need to apply individually to each instance of its class or structure, then declare it as Shared.

  • If the procedure cannot be Shared, then remove the DllImportAttribute from the declaration of this procedure.

See Also

Reference

DllImportAttribute

Shared (Visual Basic)