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

Search Results for

    SCA1045: NonCopyableAttribute Outside Its Namespace

    Declare NonCopyableAttribute in the namespace Singulink.CodeAnalysis.

    Example

    namespace MyApp;
    
    [AttributeUsage(AttributeTargets.Struct)]
    internal sealed class NonCopyableAttribute : Attribute;   // SCA1045: not recognized in this namespace
    

    How to Fix

    • Declare the class in the namespace Singulink.CodeAnalysis, or use the attribute of the Singulink.CodeAnalysis package.
    • Name it NonCopyableAttribute, where it is named NonCopyable with no suffix.
    • Suppress the warning, in a project that keeps such an attribute on purpose, for another tool.

    Details

    The analyzer recognizes the attributes by their full name. So a struct marked with such a class is copyable, a type parameter marked with it counts as not marked, and nothing else warns about it. You get this warning for:

    • an attribute class named NonCopyableAttribute that is declared in a namespace other than Singulink.CodeAnalysis;
    • an attribute class named NonCopyable with no suffix, in any namespace;
    • a struct or a type parameter of the project that is marked with such a class from a referenced assembly.

    A class that derives from such an attribute is treated like it.

    No Warning

    • A class with that name that is not an attribute.
    • The other five names: an attribute of one of them that is not recognized only means more warnings.
    • A struct of a referenced assembly: there such a mark is recognized.

    See Also

    These articles explain the rule behind this warning:

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