我有一个项目处理器,它依赖于其他两个项目。
当我编译项目时,我在Bin文件夹中得到DLL.dll和其他项目的依赖dll。 Processor.dll BusinessAction.dll和Repository.dll。
我尝试通过启动类型 ProcessRequest 类从Processor.dll调用方法。
喜欢这个
Assembly processorAssembly = Assembly.LoadFile(path + "Processor.DLL"));
Type myType= processorAssembly.GetType("Namespace.ProcessRequest");
myType.InvokeMember("Process", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, submitOfferType, new object[] { 12345 });
流程方法有一些处理逻辑并将其保存到数据库中。
当我使用InvokeMember()
调用procee方法时我得到异常无法加载文件或程序集'Namespace.BusinessAction,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null'或其依赖项之一。系统找不到指定的文件。
我是否调用方法?
答案 0 :(得分:7)
Appdomain有一个事件,如果找不到引用就会被触发:
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
在事件处理程序中,您可以手动搜索程序集:
Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string s = @"C:\lib\" + args.Name.Remove(args.Name.IndexOf(',')) + ".dll";
return Assembly.LoadFile(s);
}
答案 1 :(得分:2)
试
Assembly processorAssembly = Assembly.LoadFrom(path + "Processor.DLL"));
这将加载所有支持的DLL