You cannot to it. Here is why: let's look at the
MSDN help page http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.dllimportattribute.dllimportattribute.aspx
]: there is only one constructor with only one parameter: a DLL name. This can be not just the file name, but also a full assembly name in case if an unmanaged DLL file is included in an assembly — please look at the code sample.
That's it. I cannot be anything else. (I did not discuss positional parameters used in attribute application, they are actually properties, not call parameters.)
Now, the statement for the application of attribute (in this case, the the
method declaration) is not a "real" method call. In particular, parameters can be only the constants (or types via
). It can be an immediate constant or a explicitly declared constant (much better), but a real constant, not a read-only variable.
For that reason, it cannot be anything read from the file, a configuration file or any other file, as data read from file cannot be constant.
: not only it is impossible, but I've proved that.
Now, I'm curious: why doing that?
Perhaps you need different DLLs to be pluggable. No, this is not how it works. A linked DLL name is compiled into assembly executable module, that's it. If you need to have a pluggable unmanaged DLLs (depending on configuration or other factor) you need completely different approach: P/Invoke Windows APIs
and load DLLs during run time.