OK, say I have an application like this:
using System;
using AliensExist; // some DLL which can\'t be found...
What I want is that if the
Old question, but I feel this info needs added:
You can't try/catch a using statement, but you can try/catch the resolving of an assembly.
You have even more control if you manually load assemblies as suggested by Mike Atlas.
Also, you can manually verify an assembly before attempting to resolve by selecting from GetEntryAssembly.GetReferencedAssemblies() and comparing against something like AssemblyName.GetAssemblyName().
Of course, you can use a simple File.Exists(AssemblyPath)
in some cases, but the methods above would help verify additional assembly issues, such as version numbering or signing.
AssemblyResolve
is nice by offering an event based approach. Good if you've got high cyclomatic complexity and/or want to ride along with JIT, but less informative than an upfront verification.
Be mindful of the fail-fast principal, and the extent to which assembly resolve errors may limit functionality.