从其他路径加载dll [英] Load dlls from a different path
本文介绍了从其他路径加载dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试让我的应用程序从其他文件夹(例如C:\)加载需要运行的dll引用,以便可以移动该exe,而无需将其dll保留在同一目录中.请帮忙!
I''m trying to get my application to load the dll references that it needs to run from another folder such as C:\ so that the exe can be moved without the need to keep its dlls in the same directory. Please help!
推荐答案
只是为了使您能够移动exe并不是此设计的正当理由. .NET可以使用xcopy部署,因此移动带有exe和程序集的文件夹没有问题.
运行时如何查找程序集 [通过代码库或探针定位程序集 [
Just so you can move the exe is not a valid reason for this design. .NET can use xcopy deployment so moving the folder, with exe and assemblies, is no problem.
How the Runtime Locates Assemblies[^]
Locating the Assembly through Codebases or Probing[^]
要获取DLL中的所有信息
TO Get All Information from DLL
Assembly assembly = Assembly.LoadFrom(@"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\10.0\Additionsusersandip0.dll");
Type[] t = assembly.GetTypes();
foreach (Type tt in t)
{
if (tt.IsClass) Console.WriteLine("Name space is = " + tt.Namespace);
MethodInfo[] mi = tt.GetMethods();
Console.WriteLine(mi.ToString());
foreach (MethodInfo methodinfo in mi)
{
ParameterInfo[] pi = methodinfo.GetParameters();
Console.WriteLine(methodinfo.Name);
Console.WriteLine(methodinfo.ReturnType.ToString());
Console.WriteLine(methodinfo.ReturnParameter.ParameterType.ToString());
foreach (ParameterInfo p in pi)
{
p.GetType();
Console.WriteLine(p.Name);
Console.WriteLine(p.ParameterType);
}
}
}
调用DLL方法
To Invoke the DLL Method
Assembly myAssem = Assembly.LoadFile(strFullDummyDLLFilePath);
Type[] t = myAssem.GetTypes();
foreach (Type type in t)
{
// Invoke Method if the type is class only
if (type.IsClass)
{
// Load an assembly file into an object.
Object objAssembly = Activator.CreateInstance(type);
object[] objInputParams = null;
objResult = type.InvokeMember(strMethodName, BindingFlags.InvokeMethod,null, objAssembly, new Object[] { objIPParameters });
}
}
这篇关于从其他路径加载dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文