CA2132: Default constructors must be at least as critical as base type default constructors
Collapse the table of content
Expand the table of content

CA2132: Default constructors must be at least as critical as base type default constructors








Breaking Change



This warning is only applied to code that is running the CoreCLR (the version of the CLR that is specific to Silverlight Web applications).

The transparency attribute of the default constructor of a derived class is not as critical as the transparency of the base class.

Types and members that have the SecurityCriticalAttribute cannot be used by Silverlight application code. Security-critical types and members can be used only by trusted code in the .NET Framework for Silverlight class library. Because a public or protected construction in a derived class must have the same or greater transparency than its base class, a class in an application cannot be derived from a class marked SecurityCritical.

For CoreCLR platform code, if a base type has a public or protected non-transparent default constructor then the derived type must obey the default constructor inheritance rules. The derived type must also have a default constructor and that constructor must be at least as critical default constructor of the base type.

To fix the violation, remove the type or do not derive from security non-transparent type.

Do not suppress warnings from this rule. Violations of this rule by application code will result in the CoreCLR refusing to load the type with a TypeLoadException.


using System;
using System.Security;
using System.Runtime.InteropServices;

[assembly: SecurityRules(SecurityRuleSet.Level2)]
[assembly: AllowPartiallyTrustedCallers]

namespace TransparencyWarningsDemo

    // CA2131 error - critical type participating in equivilance
    [TypeIdentifier("3a5b6203-2bf1-4f83-b5b4-1bdc334ad3ea", "ICriticalEquivilentInterface")]
    public interface ICriticalEquivilentInterface
        void Method1();

    [TypeIdentifier("3a5b6203-2bf1-4f83-b5b4-1bdc334ad3ea", "ITransparentEquivilentInterface")]
    public interface ITransparentEquivilentInterface
        // CA2131 error - critical method in a type participating in equivilance
        void CriticalMethod();

    [TypeIdentifier("3a5b6203-2bf1-4f83-b5b4-1bdc334ad3ea", "ICriticalEquivilentInterface")]
    public struct EquivilentStruct
        // CA2131 error - critical field in a type participating in equivalence
        public int CriticalField;


© 2015 Microsoft