Colin
Colin

Reputation: 4135

SecuritySafeCriticalAttribute Not Working To Allow Partially Trusted Caller. What Am I Missing?

I'm running into a SecurityException calling one of my fully trusted methods:

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.

It seems that I should be able to overcome this by adding a SecuritySafeCriticalAttribute to my method, but it isn't working. Below is the fully trusted class being called.

Can anyone see what I could be missing or tell me what I need to do to be able to make the call from partially trusted code?

[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;
        }
    }
}

EDIT: Here are the current assembly attributes since someone asked.

[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")]

Upvotes: 2

Views: 1579

Answers (1)

user4003407
user4003407

Reputation: 22122

For full trust assembly to be callable from partial trust code, it should have either SecurityTransparentAttribute (is this case you can not have any security critical code in assembly), or AllowPartiallyTrustedCallersAttribute assembly level attribute. Absence of this attributes makes all types in full trust assembly to be security critical, and so, not accessible from partial trust code.

Upvotes: 2

Related Questions