Code Analysis Code Analysis
Code Analysis Code Analysis
DocFX + Singulink = ♥

Search Results for

    SCA1044: Conditional Attribute of the Analyzer

    Do not declare an attribute of the analyzer as conditional.

    Example

    namespace Singulink.CodeAnalysis;
    
    [Conditional("DEBUG")]                         // SCA1044: the mark is gone from the built assembly
    [AttributeUsage(AttributeTargets.Struct | AttributeTargets.GenericParameter, Inherited = false)]
    internal sealed class NonCopyableAttribute : Attribute;
    

    How to Fix

    Remove [Conditional]. Where the attribute comes from a referenced assembly, use the attribute of the Singulink.CodeAnalysis package, or declare one that is not conditional.

    Details

    One of the analyzer's six attributes is declared [Conditional]. The compiler leaves a conditional attribute out of the assembly unless its symbol is defined, so the marks hold inside the project but are gone in every project that uses it.

    • At a use: you also get this warning at every use of such an attribute that a referenced assembly declares, where none of its symbols is defined. The mark is missing from the assembly that is being built.
    • Derived classes: an attribute that derives from a conditional class is conditional too, and so is a class that derives from a conditional NonCopyableAttribute, which marks just as NonCopyableAttribute does.

    See Also

    These articles explain the rule behind this warning:

    • How the Attributes Are Recognized - the exact rules.
    © Singulink. All rights reserved.