尝试运行没有 dll 的 exe 文件时如何显示错误消息?
我有一个 C# 应用程序,其中有一个通过引用添加的 dll。 当我尝试从 Windows 运行 exe 文件(编译后)并且 dll 被重命名时,我希望应用程序显示错误消息。
我怎样才能在代码中做到这一点?
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.
How can I do it in code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 exe 找不到任何所需的 dll,它应该已经显示错误。大致如下:
您没有得到此信息的事实意味着以下几件事之一:
a) 您的程序实际上并未引用该 dll。
b) 您已将 dll 链接到 exe 中。
c) CLR 在其他地方找到了 DLL(感谢 Pondidum)
If the exe can't find any required dlls it should already display an error. Something along the lines of:
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)
在 .NET 应用程序中,直到第一次尝试使用缺少的 DLL 中的类时才会出现错误。
有以下几种可能性:
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:
您的 exe 也可能在其他地方找到所需的程序集。要检查它在哪里搜索所需的程序集,请查看MSDN 上的这篇文章。
另一种可能性是使用 AssemblyLoad 或 < a href="http://msdn.microsoft.com/en-us/library/system.appdomain.assembleresolve.aspx" rel="nofollow noreferrer">AssemblyResolve 事件以获取有关哪些程序集的更多信息(未)加载。
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.