代码之家  ›  专栏  ›  技术社区  ›  Jason Kleban

封闭源程序集的“无法验证的代码未通过策略检查”

  •  2
  • Jason Kleban  · 技术社区  · 16 年前

    我试图在MSI安装例程期间从C程序的资源流中动态加载一些(购买的)程序集,但我得到的是“无法验证的代码未通过策略检查”。

    我在网上读到一些关于使用/clr:safe编译嵌入式程序集的提示,但我没有这个选项。有办法解决这个政策检查吗?

    谢谢。

    3 回复  |  直到 12 年前
        1
  •  3
  •   tomfanning    13 年前

    加载不可验证代码的唯一方法是从禁用验证的完全信任进程(或可能是应用程序域)加载。

    编辑:我不是编造的, one of the C# language designers said "Unverifiable code requires full trust and is generally to be avoided"

        2
  •  1
  •   Steve Mitcham    15 年前

    这可能不再相关,但我最近遇到了同样的问题。如果获取流并将其粘贴到临时文件中,则可以使用assembly.loadfrom加载程序集。

        3
  •  1
  •   hriziya    12 年前

    已经太晚了,但它可能会帮助别人。

    我已经用过 Sqlite DLL 在我的项目中,当我在沙箱环境中部署代码时,我遇到了异常(见下文)

    [FileLoadException: Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
    
    [FileLoadException: Could not load file or assembly 'System.Data.SQLite, Version=1.0.79.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)]
    

    我补充说 trust level 在web.config文件中的system.web及其正常工作。

    <trust level="Full|High|Medium|Low|Minimal" originUrl="url"/>