at program startup, i would like to find out if the application has all the dlls it requires to run. is it possible using reflection see what dlls are used by my application, name, version etc. then i can use FILE.Exists to check and see if the dlls are located in the directory. I want to gracefully exit if the dlls are missing instead of just crashing.
Asked
Active
Viewed 33 times
0
-
You are trying to solve the wrong problem. The CLR already provides you with an eminently readable and diagnosable exception when a DLL is missing. The problem is that you just "crash". What you must do is not crash but display that exception and exit gracefully. Writing an event handler for the AppDomain.CurrentDomain.UnhandledException event is never optional. – Hans Passant Apr 09 '16 at 06:56
-
http://stackoverflow.com/a/3133249/17034 – Hans Passant Apr 09 '16 at 06:58
-
i have done that. What the client wants is to have the program start up and then check all the dlls and provide a message like exiting program missing dll such and such please call support – Bill Gower Apr 09 '16 at 07:04
-
Just tell him that you use Reflection so there isn't any way to implement the feature reliably. Solve his *real* problem and give him an installer. And update your question to remove the highly misleading "crash" nonsense, you can never get a good answer when you fib. – Hans Passant Apr 09 '16 at 07:06
-
You can't detect all assembly's needed by a program because some of them may be dynamically loaded. There is absolute no way to find that assembly's because the user may select them. You can only access all referenced assemblies. Using recursion you can find all of them. But you can't do that in the assembly itself. You can create a caller exe that doesn't need any other assembly and load the entry assembly of your real application and reflect for all referenced assemblies recursively. But it is still impossible to find dynamically loaded assemblies. – Sebastian Schumann Apr 09 '16 at 08:42