views:

24

answers:

1

I have a library that contains a class that references dwm. If this library is use in an XP system but the class is not used, would this cause an error?

Supposed this library was to be used on WP7 or XNA? Would this cause an error?

+3  A: 

The runtime will not try to reference the DLL until you call the function. If your program never calls the method that references the missing DLL, then there will be no error.

Jim Mischel
Is this behavior by contract or just an implementation detail of the current runtime version?
CodeInChaos
I suspect that it's by contract. Imagine if the runtime were to, at program startup, try to resolve all of the external methods that could conceivably be called by the program. That would take a very long time, even for a small program. The JIT compiler compiles code on a first-call basis, so if you don't call a method then there's no code generated for it. If there's no code generated for it, then it can't cause an error.
Jim Mischel