SecuritySafeCriticalAttribute 不适用于允许部分受信任的调用方。我错过了什么?
SecuritySafeCriticalAttribute Not Working To Allow Partially Trusted Caller. What Am I Missing?
我 运行 遇到调用我完全信任的方法之一的 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 来克服这个问题,但它不起作用。下面是被调用的完全受信任的 class。
任何人都可以看到我可能遗漏了什么或告诉我我需要做什么才能从部分受信任的代码进行调用吗?
[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")]
对于可从部分信任代码调用的完全信任程序集,它应该具有 SecurityTransparentAttribute
(在这种情况下您不能在程序集中包含任何安全关键代码)或 AllowPartiallyTrustedCallersAttribute
程序集级别属性。缺少此属性会使完全信任程序集中的所有类型都成为安全关键,因此无法从部分信任代码访问。
我 运行 遇到调用我完全信任的方法之一的 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 来克服这个问题,但它不起作用。下面是被调用的完全受信任的 class。
任何人都可以看到我可能遗漏了什么或告诉我我需要做什么才能从部分受信任的代码进行调用吗?
[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")]
对于可从部分信任代码调用的完全信任程序集,它应该具有 SecurityTransparentAttribute
(在这种情况下您不能在程序集中包含任何安全关键代码)或 AllowPartiallyTrustedCallersAttribute
程序集级别属性。缺少此属性会使完全信任程序集中的所有类型都成为安全关键,因此无法从部分信任代码访问。