【问题标题】:Load Embedded Assembly加载嵌入式程序集
【发布时间】:2012-02-23 23:33:46
【问题描述】:

我正在尝试在运行时在服务器端 DLL 上加载嵌入式程序集。我嵌入的程序集是我自己的代码。

我在尝试加载程序集时收到 Unverifiable code failed policy check 错误。

有没有办法解决这个问题?

代码如下:

    byte[] resource = null;

    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(name))
    {
        if (stream != null)
        {
            resource = new byte[stream.Length];
            stream.Read(resource, 0, (int)stream.Length);
        }
    }

    AppDomain.CurrentDomain.Load(resource);

编辑:

有点摸不着头脑,但我尝试先将 DLL 保存到磁盘,然后以这种方式加载。这是我现在得到的:无法加载文件或程序集或其依赖项之一。给定的程序集或代码库无效。

【问题讨论】:

标签: c# embedded-resource


【解决方案1】:

找到解决方案,如果有人偶然发现这篇文章:

-C# 将 not allow 您从字节加载程序集,除非您处于高安全性上下文中。

-有趣的是,如果你有权限先保存到文件,然后使用Assembly.Load(filename)(我错误地使用AppDomain.CurrentDomain.Load(filename))加载程序集没有问题。

【讨论】:

    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 2018-10-15
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多