views:

85

answers:

3

Hi

I have a c# application which has a dll added by reference. when I try to run the exe file from windows (after compilation) and the dll is renamed I want the application to show an error message ;

Does someone know how can I do it in code?

Thanks.

+3  A: 

If the exe can't find any required dlls it should already display an error. Something along the lines of:

The program can't start because example.dll is missing from your computer. Try reinstalling the program to fix this problem.

The fact that you're not getting this implies one of several things:

a) The dll isn't actually referenced by your program.

b) You've linked the dll into the exe.

c) The DLL has been found elsewhere by the CLR (thanks Pondidum)

ChrisF
also possible that the DLL has been found elsewhere by the CLR
Pondidum
+1  A: 

In a .NET app you won't get an error until the first time you try to use a class in the missing DLL.

A couple of possibilities:

  • Write code that runs on program startup and calls dummy methods on one class in each DLL
  • Recursively call Assembly.GetReferencedAssemblies() and build a list of missing DLLs
Tim Robinson
+1  A: 

Also it would be possible that your exe finds the needed assembly somewhere else. To check where it search for a needed assembly check out this article on MSDN.

Another possibility would be to use the AssemblyLoad or AssemblyResolve events to get more informations about which assemblies are (not) loaded.

Oliver