.net - CodeAccessSecurityEngine 异常

标签 .net exception code-access-security

当我的应用程序启动时,我的两个用户(数千名用户中)遇到了奇怪的异常。我无法通过 Google、MSDN 或 Reflector 找到任何有关它的有用信息。

enter image description here

如果您想复制粘贴这些内容,请写出以下内容:

External component has thrown an exception.

Stack trace:
  at System.Security.CodeAccessSecurityEngine.CheckNReturnSO(PermissionToken permToken, CodeAccessPermission demand, StackCrawlMark& stackMark, Int32 unrestrictedOverride, Int32 create)
  at System.Security.SecurityRuntime.Assert(PermissionSet permSet, StackCrawlMark& stackMark)
  at System.Security.PermissionSet.Assert()
  at System.Windows.Forms.WindowsFormsSynchronizationContext.InstallIfNeeded()
  at System.Winfows.Forms.Control..ctor(Boolean autoInstallSyncContext)
  .....
  at GrasshopperPlugin.GrasshopperPlugin.OnLoadPlugIn() //This is the first call to my assembly.
  at RhDN_NativePlugInBase<CRhinoUtilityPlugIn,RMA::Rhino::MRhinoUtilityPlugIn>.OnLoadPlugIn() //This is the C++/CLI mixed mode SDK that loads my .NET assembly.

这是什么意思?为什么会发生这种情况?我该如何修复/检测这个问题?

最佳答案

我使用 ILSpy 检查 WindowsFormsSynchronizationContext.InstallIfNeeded 的代码。

它添加了以下权限集:

new PermissionSet(PermissionState.Unrestricted).Assert();

然后调用

AsyncOperationManager.SynchronizationContext = new WindowsFormsSynchronizationContext();

它在 setter 上具有以下属性:

[PermissionSet(SecurityAction.LinkDemand, Name = "FullTrust")]

如果我正确理解安全模型,您必须确保允许用户在“FullTrust”模式下运行。

关于.net - CodeAccessSecurityEngine 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6997404/

相关文章:

c# - 绑定(bind)行选择

c++ - 如何抛出超出范围的 C++ 异常

java - Android:将敏感字符串放入我的 Java 代码中是否安全?

android - Android 平台是否有任何专注于安全性的编码指南?

android - 如何读取 keystore 值?

.net - 通过加密保护软件

c# - 我应该如何比较两个列表中的值?

c# - 在 HTML 选择控件 (.NET/C#) 中的列表项上设置自定义属性

java - 如何避免创建自定义异常类,同时仍然在适当的抽象级别抛出异常?

java - Android - 在提交之前(期间)检查 FragmentManager 事务是否存在由 fragment 代码引起的异常