How do I dynamically load raw assemblies that contains unmanaged code?(bypassing 'Unverifiable code failed policy check' exception)

烈酒焚心 提交于 2019-12-02 22:32:51
Hans Passant

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

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:

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

UPDATE: link fixed with archive.org backup copy.

The problem is that the CLR does not perform the normal DLL loading steps - like mapping the dlls separate sections into different pages, adjusting fixups, etc. When an assembly is loaded from raw bytes, those raw bytes are mapped into memory as is, and only managed meta-data is read. No amount of evidence or security settings will change this behavior.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!