'System.Runtime.InteropServices.DllImportAttribute' 無法套用至執行個體方法

更新:2007 年 11 月

已利用 DllImportAttribute 宣告非共用程序。

Common Language Runtime (CLR) 在指定 .NET Framework 以外的 Unmanaged 動態連結程式庫 (DLL) 中所定義的取代程序時,辨認出此屬性 (Attribute) 及其 EntryPoint 屬性 (Property)。當程式碼呼叫的程序已套用 DllImportAttribute 時,Common Language Runtime 會改為呼叫指定的 Unmanaged 程序。

因為 .NET Framework 外的 Unmanaged 平台不會以 .NET Framework 所用的相同方式支援非共用程序,所以您無法使用非共用程序將它們交互操作。

錯誤 ID:BC31529

若要更正這個錯誤

  • 如果程序不需要個別地套用至其類別或結構的每一個執行個體,請將它宣告為 Shared。

  • 如果程序不能是 Shared,請從這個程序的宣告中移除 DllImportAttribute

請參閱

參考

DllImportAttribute

Shared (Visual Basic)