当我的应用程序启动时,我的两个用户(数千名用户中)遇到了奇怪的异常。我无法通过 Google、MSDN 或 Reflector 找到任何有关它的有用信息。
如果您想复制粘贴这些内容,请写出以下内容:
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/