本文主要是介绍位于Intranet上包含unsafe的托管代码在本机运行时的 fileloadexception,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
首先请看这个帖子:Unable to load assembly .
默认情况(默认的CAS policy)下,包含Unsafe代码(managed C++, 标记有unsafe的C#代码)的assembly是不能被load的。所以在CLR 加载这个程序集也就是在程序的main函数开始执行之前,就有异常爆出。
其实真正的Exception 就是: PolicyException SecurityManager.ResolvePolicy。
对于这个问题, Don box在Essential.NET里面说的非常清楚:
“The use of unmanaged pointers results in code that is not verifiably type-safe. The ability to execute code that is not verifiably type-safe is a highly trusted security permission that, by default, the CLR denies to all code not originating from the local file system. In particular, the assembly containing the non-verifiable code must request (and be granted) the SecurityPermissionFlag.SkipVerification permission in its assembly manifest. On a default installation of the CLR, this permission is not granted to code loaded from remote file systems, so the only way to get non-verifiable code to execute is to dupe a user into copying it to an executable area of the local file system. Of course, the administrator or end user may explicitly grant permission to run code that is known to be trusted, but this as well requires that someone with trusted access to the deployment machine take a deliberate action.
Because of the role of C-style pointers in C++ programs, the C++ compiler emits only non-verifiable code. So your program from intranet is blocked by the CLR security system by default.”
这篇关于位于Intranet上包含unsafe的托管代码在本机运行时的 fileloadexception的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!