Can I catch a missing dll error during application load in C#?

You can use AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

  Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
    }

To manually find the assembly if it can't find it automaticaly.


Extending Josh's answer.

Assemblies in .Net are loaded on demand by the CLR. Typically an assembly load won't be attempted until a method is JIT'd which uses a type from that assembly.

If you can't catch the assembly load failure with a try/catch block in the main method, it's likely beceause you're using a type from the assembly within the try/catch. So the exception occurs before the main method is actually run.

Try putting all of the code from the main method in a different function. Then call that function within the try/catch block and you should see the exception.

Tags:

C#

.Net

Dll