Jan H.
Jan H.

Reputation: 41

C# DllImport not found in context, but Interpor Services are bound in

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.

Upvotes: 1

Views: 1050

Answers (1)

Dmitry
Dmitry

Reputation: 14059

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()
    {
        ...
    }
}

Upvotes: 2

Related Questions