Thanks Jon. That's what I didn't understand. When I looked here:
http://msdn2.microsoft.com/en-us/lib...attribute.aspx
It didn't specify that my DllName had to be a constant so I assumed it could
change.
"Jon Skeet [C# MVP]" wrote:
> On May 3, 2:33 pm, SAL <S...@discussions.microsoft.com> wrote:
>
> <snip>
>
> > I have not used the DllImport Attribute before, but what I can see it takes
> > a String value for the DllName, and a set of NamedParameters that are
> > optional.
> >
> > Can anyone tell me what I am doing wrong and how to correct it?
>
> As the compiler error says, the value of an attribute argument (the
> DLL name in your case) must be a constant. That rules out using the
> result of a method call.
>
> If your method just chose between two constants based on DEBUG, you
> could just have two constants - but it's using the system directory,
> which is dynamic.
>
> (To understand why this all needs to be constant - the value gets
> compiled directly into the assembly as a constant - there's no runtime
> initialization.)
>
> Jon
>
>