Error del compilador CS0601

Actualización: noviembre 2007

Mensaje de error

El atributo DllImport se debe especificar en un método marcado como 'static' y 'extern'.
The DllImport attribute must be specified on a method marked 'static' and 'extern'

Se utilizó el atributo DllImport en un método que no tenía las palabras clave de acceso correctas.

El código siguiente genera el error 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 ()
   {
   }
}