如何从嵌入式资源加载DLL?

时间:2013-12-04 22:41:21

标签: c# .net-assembly

我有两个dll(xNet.dllag.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?

1 个答案:

答案 0 :(得分:-1)

using xNet;
using ag;

太难了?