我遇到了一个SecurityException,调用了一个完全可信的方法:
Attempt by security transparent method '(partially trusted method)' to access
security critical method 'ContainerSingleton.GetExportedValue<ICloudApplication>()'
failed.
Assembly '(my assembly)' is partially trusted, which causes the CLR to make
it entirely security transparent regardless of any transparency annotations
in the assembly itself. In order to access security critical code, this
assembly must be fully trusted.
似乎我应该能够通过在我的方法中添加SecuritySafeCriticalAttribute来克服这个问题,但它不起作用。下面是被称为完全受信任的类。
任何人都可以看到我可能遗失的内容,或者告诉我需要做些什么才能从部分受信任的代码中拨打电话?
[SecuritySafeCritical]
public class ContainerSingleton
{
static ContainerSingleton() {}
[SecuritySafeCritical]
public static T GetExportedValue<T>()
{
return ContainerInstance.GetExportedValue<T>();
}
private static CompositionContainer compositionContainer;
public static CompositionContainer ContainerInstance
{
get
{
if (!IsInitialized)
{
//initialize
}
return compositionContainer;
}
}
public static bool IsInitialized
{
get { return compositionContainer != null; }
}
public static void Initialize(CompositionContainer container)
{
compositionContainer = container;
}
}
}
编辑:以下是有人询问时的当前装配属性。
[assembly: AssemblyTitle("...assembly name...")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("...assembly name...")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("...")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
答案 0 :(得分:2)
对于可从部分信任代码调用的完全信任程序集,它应该具有SecurityTransparentAttribute
(在这种情况下,您不能在程序集中包含任何安全关键代码)或AllowPartiallyTrustedCallersAttribute
程序集级别属性。缺少此属性会使完全信任程序集中的所有类型都成为安全关键,因此无法从部分信任代码访问。