【发布时间】:2013-12-04 22:41:20
【问题描述】:
我有两个 dll(xNet.dll 和 ag.dll),我想在我的项目中使用它们。
我将它们添加到资源中,声明构建操作是嵌入式资源。 接下来我有这样的代码来加载第一个 dll:
public Form1()
{
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
InitializeComponent();
}
private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly assembly = Assembly.GetExecutingAssembly();
string assemblyName = args.Name.Split(',')[0];
using (Stream stream = assembly.GetManifestResourceStream("Yandex.dll.xNet.dll"))
{
if (stream == null)
return null;
byte[] rawAssembly = new byte[stream.Length];
stream.Read(rawAssembly, 0, (int)stream.Length);
return Assembly.Load(rawAssembly);
}
}
如何加载第二个dll?
【问题讨论】:
-
你为什么不能把它们添加为参考?
标签: c# .net-assembly