c# 使用 Assembly.Load 从内存中加载乘法程序集
c# using Assembly.Load to load multiply assembly from memory
我有2个程序集应该从内存中加载,我使用下面的代码来实现它但是它不能工作。帮帮我,谢谢!
Assembly.Load(File.ReadAllBytes("b.dll"));
var assembly = Assembly.Load(File.ReadAllBytes("a.dll"));//a.dll referenced b.dll
var type = assembly.GetTypes().First(p => p.FullName == "Namespace1.Type1");
type.GetMethod("StaticMethod1", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { });//it throw an exception, can't load file or assembly b.dll
使用 Assembly.Load
从字节数组加载程序集,加载程序集但不在应用程序域中以其名称注册它。为了在运行时希望加载具有特定名称的特定程序集时从字节数组提供您自己的程序集,您需要实现 AppDomain.AssemblyResolve
事件。
请参阅 this question and the answer 示例代码。
我有2个程序集应该从内存中加载,我使用下面的代码来实现它但是它不能工作。帮帮我,谢谢!
Assembly.Load(File.ReadAllBytes("b.dll"));
var assembly = Assembly.Load(File.ReadAllBytes("a.dll"));//a.dll referenced b.dll
var type = assembly.GetTypes().First(p => p.FullName == "Namespace1.Type1");
type.GetMethod("StaticMethod1", BindingFlags.Static | BindingFlags.Public).Invoke(null, new object[] { });//it throw an exception, can't load file or assembly b.dll
使用 Assembly.Load
从字节数组加载程序集,加载程序集但不在应用程序域中以其名称注册它。为了在运行时希望加载具有特定名称的特定程序集时从字节数组提供您自己的程序集,您需要实现 AppDomain.AssemblyResolve
事件。
请参阅 this question and the answer 示例代码。