This documentation is archived and is not being maintained.

'System.Runtime.InteropServices.DllImportAttribute' cannot be applied to a method that is generic or nested in a generic type 

A procedure is declared with the DllImportAttribute, but either the procedure is generic or it is contained in a generic class or structure.

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 recognize generic types, you cannot interoperate with them using generic types.

Error ID: BC31526

To correct this error

  • If neither the procedure nor its container needs to be generic, then remove the Of clauses so that they are not generic.

  • If the procedure or its container needs to be generic, then remove the DllImportAttribute from the declaration of this procedure.

See Also

Show: