如何检查C#中是否有库(dll)?

时间:2022-09-02 09:53:39

How do I check if a library (dll) is available at runtime before I call it?

在调用之前,如何检查库(dll)是否在运行时可用?

2 个解决方案

#1


You can use System.IO.File.Exists to check for the file if you know where it's located.

如果知道文件的位置,可以使用System.IO.File.Exists检查文件。

You can use System.Reflection.Assembly.LoadFrom to load it.

您可以使用System.Reflection.Assembly.LoadFrom来加载它。

You'll need to use reflection to call methods in the dll if you use this form of late binding.

如果使用这种形式的后期绑定,则需要使用反射来调用dll中的方法。

#2


The AppDomain.AssemblyLoad and AppDomain.AssemblyResolve events occur on load and load failure, respectively. If you handle these events you can determine which assemblies loaded and which failed.

AppDomain.AssemblyLoad和AppDomain.AssemblyResolve事件分别在加载和加载失败时发生。如果处理这些事件,则可以确定加载的程序集和失败的程序集。

#1


You can use System.IO.File.Exists to check for the file if you know where it's located.

如果知道文件的位置,可以使用System.IO.File.Exists检查文件。

You can use System.Reflection.Assembly.LoadFrom to load it.

您可以使用System.Reflection.Assembly.LoadFrom来加载它。

You'll need to use reflection to call methods in the dll if you use this form of late binding.

如果使用这种形式的后期绑定,则需要使用反射来调用dll中的方法。

#2


The AppDomain.AssemblyLoad and AppDomain.AssemblyResolve events occur on load and load failure, respectively. If you handle these events you can determine which assemblies loaded and which failed.

AppDomain.AssemblyLoad和AppDomain.AssemblyResolve事件分别在加载和加载失败时发生。如果处理这些事件,则可以确定加载的程序集和失败的程序集。