Errore del compilatore CS0601

Aggiornamento: novembre 2007

Messaggio di errore

L'attributo DllImport deve essere specificato in un metodo contrassegnato come 'static' e 'extern'.
The DllImport attribute must be specified on a method marked 'static' and 'extern'

L'attributo DllImport è stato utilizzato in un metodo che non presenta le parole chiave di accesso corrette.

Il seguente codice di esempio genera l'errore CS0601:

// CS0601.cs
using System.Runtime.InteropServices;
using System.Text;

public class C
{
   [DllImport("KERNEL32.DLL")]
   extern int GetCurDirectory(int bufSize, StringBuilder buf);   // CS0601
   // Try the following line instead:
   // static extern int GetCurDirectory(int bufSize, StringBuilder buf);
}

public class MainClass
{
   public static void Main ()
   {
   }
}