1

I have a problem with my compiler not being able to import kernel32.dll, althrough I'm using System.Runtime.InteropServices. Here is the Code:

    using System;
    ...
    using System.Runtime.InteropServices;

    namespace server
    {
        class Debugconsole
        {
            public void Initialise()
            {
                [DllImport("kernel32.dll")]
                ...
            }
        }
    }

It throws a whole bunch of syntaxerrors and "Can't find "DllImport" in current context."

Thanks for your help.

Jan H.
  • 41
  • 8
  • 2
    You've misplaced the `DllImport` inside a method, where it should be placed outside. Check out [this answer](http://stackoverflow.com/questions/6076717/where-to-put-dllimport). – Vlad Oct 20 '14 at 18:26

1 Answers1

2

Attributes cannot be used inside a method.
You should move it out of your method:

class Debugconsole
{
    [DllImport("kernel32.dll")]
    ... the static extern method declaration ...

    public void Initialise()
    {
        ...
    }
}
Dmitry
  • 13,797
  • 6
  • 32
  • 48