【发布时间】:2014-05-10 15:02:50
【问题描述】:
我有一个部分信任的 AppDomain,我在其中运行一个完全信任的调试窗口。使用PermissionSetAttribute 获取权限我可以创建窗口并用它做很多事情,但有时在数据绑定期间会抛出SecurityException。
一个容易重现的案例抛出这个:Property accessor 'Namespace' on object 'System.RuntimeType' threw the following exception:'Request failed.'。深入研究异常,我可以看到它是在需要完全信任时抛出的。
没问题,调试窗口程序集完全信任,我只需要断言它。但是当我查看内部SecurityException 的堆栈跟踪时,我看到了这个:
at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)
at System.Security.CodeAccessSecurityEngine.Check(PermissionSet permSet, StackCrawlMark& stackMark)
at System.Security.PermissionSet.Demand()
at System.SecurityUtils.DemandGrantSet(Assembly assembly)
at System.SecurityUtils.DemandReflectionAccess(Type type)
at System.SecurityUtils.MethodInfoInvoke(MethodInfo method, Object target, Object[] args)
at System.ComponentModel.ReflectPropertyDescriptor.GetValue(Object component)
到此结束,ReflectPropertyDescriptor.GetValue。
在 Visual Studio 的调用堆栈窗口中,我可以在堆栈的最顶端看到 ReflectPropertyDescriptor.GetValue。 那个堆栈一直追溯到调试窗口的创建和我在那里执行的安全断言,这正是我想要的。
为什么堆栈会像这样被一分为二?我怎样才能阻止它发生?
我正在使用 .Net 4.0 安全性(即 2 级)。
【问题讨论】:
标签: c# wpf stack-trace code-access-security