This question inspired me to ask the following question. Does the DllImport attribute always loads the specific DLL even when you're not calling/using the method.
For example when you have the following code:
static class Program {
[DllImport("kernel32.dll")]
static extern bool AllocConsole();
static void Main()
{
if (true)
{
//do some things, for example starting the service.
}
else
{
AllocConsole();
}
}
}
Now when the application is started the AllocConsole will never be fired but will the dll be loaded anyway?