【发布时间】:2011-03-18 20:50:44
【问题描述】:
我正在创建一个将在沙盒环境中运行代码的应用程序。这个环境应该只允许不受信任的代码处理它明确给出的资源并返回一个定义的数据类型。我正在使用本文中的主体来设置沙箱:
How to: Run Partially Trusted Code in a Sandbox
我还有一些代码需要在沙盒环境中运行。不幸的是,当我尝试将类型设置为在沙箱中运行时,出现以下错误:
类型违反了继承安全规则:“MyTypeRunningInSandbox”。派生类型必须与基类型的安全可访问性相匹配,或者难以访问。
我不知道为什么会出现这个错误,因为基类型和派生类型都是由我创建的,而且两者都不应该比另一个更安全。
我的应用结构(帮助您理解):
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 );
关于如何解决此问题的任何想法?
【问题讨论】: