2011-03-18 110 views
2

我正在创建一个将在沙盒环境中运行代码的应用程序。这个环境应该只允许不受信任的代码处理明确给定的资源并返回一个定义的数据类型。我使用这个文章中找到设置沙箱校长:错误:沙盒时出现“继承安全规则违反”

How to: Run Partially Trusted Code in a Sandbox

我也有一些代码,需要将沙盒环境中运行。不幸的是,当我尝试安装类型,我发现了以下错误沙盒中运行:

Inheritance security rules violated by type: 'MyTypeRunningInSandbox'. Derived types must either match the security accessibility of the base type or be less accessible.

我不知道我为什么会得到这个错误的基本类型和派生类型两者都是由我创造,并且两者都不应该比另一个更安全。

我的应用程序Strucure(以帮助您了解):

TypeLoader class 
    \ 
    Trusted Sandbox Manager (i.e. sets up a the new sandbox) 
    \    (the error is happening in this class while creating the 
     |    new app domain) 
     | 
     |Untrusted Sandbox Manager (i.e. runs the untrusted code) 

如果你比较我的解决方案对于Microsoft文章上面,我的代码失败在相当于以下行:

ObjectHandle handle = Activator.CreateInstanceFrom(
newDomain, typeof(Sandboxer).Assembly.ManifestModule.FullyQualifiedName, 
     typeof(Sandboxer).FullName); 

有关如何解决此问题的任何想法?

回答

5

我终于明白了这一点。我需要更好地理解可信程序集和强名称的工作原理。问题在于我的不可信类型的基类型位于一个程序集中,该程序集使用与之前设置为可信的相同的强名称密钥进行了签名。当我将基础类型移动到具有不同强名称键的新程序集时,它开始工作良好。现在看来如此明显,无法想象为什么我以前没有看到它。

感谢任何给予此考虑的人!

相关问题