我正在使用插件架构创建应用程序。要加载外部DLL文件,我使用MEF框架。所有这些外部dll都在不同的域中运行。我想允许创建模块的人定义模块将需要执行的PermissionSets。但是,由于container.ComposeParts(this);
抛出了这样的异常,我在加载这样的库时遇到了问题:
Attempt by security transparent method 'System.ComponentModel.Composition.ReflectionModel.ReflectionComposablePart.Crea
teInstance(System.Reflection.ConstructorInfo, System.Object[])' to access
security critical method
'Sth.Plugins.Dummy.DummyConfigurer..ctor()' failed.
Assembly 'System.ComponentModel.Composition, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089' is marked with the
AllowPartiallyTrustedCallersAttribute, and uses the level 2 security
transparency model. Level 2 transparency causes all methods in
AllowPartiallyTrustedCallers assemblies to become security transparent by
default, which may be the cause of this exception.
目前,我正在使用此类权限:
var permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(new SecurityPermission(SecurityPermissionFlag.Execution | SecurityPermissionFlag.ControlThread));
permissions.AddPermission(new FileIOPermission(FileIOPermissionAccess.Read | FileIOPermissionAccess.PathDiscovery, _codeStorage.RuntimeFolder));
我在想,当我将DLL中加载的类标记为SecuritySafeCritical
时,它会起作用,但我错了。
我怎样才能让它发挥作用?
答案 0 :(得分:0)
由于这篇文章及其回复,我设法解决了这个错误:
the-demand-was-for-permissionset-class-system-security-permissionset-version