在vb.net中检查外部依赖关系 [英] Checking for external dependances in vb.net
问题描述
我以前从未真正做过什么,但是什么是确保我的应用程序使用的任何外部程序集/dll可用以及正确版本的最佳方法是什么.
Something i've never really done before, but what is the best way to make sure that any external assemblies/dll's that my application uses are available, and possibly the correct version.
我写了一个依赖于System.Data.SQLite.dll的应用程序,我去了缺少dll的计算机上对其进行测试,而我的应用程序由于该dll丢失而抛出了运行时异常.我该如何捕获此错误?
I wrote an app that relies on the System.Data.SQLite.dll, i went to test it on a machine where that dll was missing, and my app just threw up a runtime exception because the dll was missing. How can i trap this error?
推荐答案
您要做的是使用反射检查并查看程序集是否可以加载到内存中.将其包装在try..catch块中,并处理由此而来的任何特定异常.
What you want to do is use reflection to check and see if the assembly can be loaded into memory. Wrap that up in a try..catch block and handle any of the specific exceptions that come from it.
Try
Assembly.Load("System.Data.SQLite, Version=1.0.22.0, Culture=neutral, PublicKeyToken=DB937BC2D44FF139");
Catch ex As FileNotFoundException
//do something here
End Try
这篇关于在vb.net中检查外部依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!