Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CA2135: Level 2 assemblies should not contain LinkDemands
Collapse the table of content
Expand the table of content

CA2135: Level 2 assemblies should not contain LinkDemands







Breaking Change


A class or class member is using a LinkDemand in an application that is using Level 2 security.

LinkDemands are deprecated in the level 2 security rule set. Instead of using LinkDemands to enforce security at just-in-time (JIT) compilation time, mark the methods, types, and fields with the SecurityCriticalAttribute attribute.

To fix a violation of this rule, remove the LinkDemand and mark the type or member with the SecurityCriticalAttribute attribute.

Do not suppress a warning from this rule.

In the following example, the LinkDemand should be removed and the method marked with the SecurityCriticalAttribute attribute.

using System;
using System.Security;
using System.Security.Permissions;

namespace TransparencyWarningsDemo

    public class MethodsProtectedWithLinkDemandsClass
        // CA2135 violation - the LinkDemand should be removed, and the method marked [SecurityCritical] instead
        [SecurityPermission(SecurityAction.LinkDemand, UnmanagedCode = true)]
        public void ProtectedMethod()
© 2015 Microsoft