开发者

How can I show an error message when trying to run an exe file without its dlls?

I开发者_StackOverflow中文版 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.

How can I do it in code?


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)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜