如何动态地加载的原始程序集包含非托管code?(绕过“无法验证code失败的政策支票”除外) [英] How do I dynamically load raw assemblies that contains unmanaged code?(bypassing 'Unverifiable code failed policy check' exception)

查看:246
本文介绍了如何动态地加载的原始程序集包含非托管code?(绕过“无法验证code失败的政策支票”除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给使用 System.Data.SQLite.DLL 其中的一个例子是一个混合装配与非托管code:  如果我执行这样的:

I'm going to give an example of using System.Data.SQLite.DLL which is a mixed assembly with unmanaged code: If I execute this :

  var assembly= Assembly.LoadFrom("System.Data.SQLite.DLL")

没有抛出异常,但如果我这样做:

No exceptions are thrown, but if I do this :

  var rawAssembly = File.ReadAllBytes("System.Data.SQLite.DLL");
  var assembly = Assembly.Load(rawAssembly);

在CLR抛出一个FileLoadException无法验证code失败的政策支票。(从HRESULT异常:0x80131402)。  比方说,我试图加载一个孩子的AppDomain本次大会,我怎么能自定义应用程序域的安全性,让我通过策略检查?

The CLR throws a FileLoadException with "Unverifiable code failed policy check. (Exception from HRESULT: 0x80131402)". Let's say I'm trying to load this assembly on a child AppDomain, how can I customize the AppDomain's security to allow me pass the policy check?

推荐答案

我们有一个糟糕的异常信息的受害者。装载程序集用的Assembly.Load(byte []的)包含在不支持的非托管code。这是此主题<一href="http://connect.microsoft.com/VisualStudio/feedback/details/97801/loading-mixed-assembly-with-assembly-load-byte-throw-exception-changed-behaviour"相对=nofollow>反馈项。

We are the victim of a crummy exception message. Loading assemblies with Assembly.Load(byte[]) that contain unmanaged code in not supported. This is the subject of this feedback item.

更新:链接的反馈项目消失了,删除的清理,在VS2012释放时间的一部分。它的唯一部分仍可恢复是这样的片段,从另一个网页复制:

UPDATE: the linked feedback item is gone, deleted as part of the cleanup at VS2012 release time. The only part of it could still recover is this fragment, copied from another web page:

[...]我们只允许加载ILONLY图像[...]因为别的是不是安全 -

"[…] we only allow ILOnly images to be loaded […] since anything else is not safe"--

这篇关于如何动态地加载的原始程序集包含非托管code?(绕过“无法验证code失败的政策支票”除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆