I did a little test. The following program works fine:
static class Program { [DllImport("doesnotexist.dll")] static extern bool AllocConsole(); static void Main() { if (false) AllocConsole(); } }
The following program throws a DllNotFoundException on the AllocConsole () line.
static class Program { [DllImport("doesnotexist.dll")] static extern bool AllocConsole(); static void Main() { if (true) AllocConsole(); } }
So it looks like the dll only loads on the first call.
source share