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

Search Results for

    SCA1020: Member of an Unmarked Generic Not on the Symbol List

    Do not use a member of an unmarked generic with a non-copyable type.

    Example

    var list = new List<LockGuard>();              // OK: on the symbol list
    list.Add(myLock.Enter());                      // OK: on the symbol list
    LockGuard[] all = list.ToArray();              // SCA1020: not on the symbol list, it copies
    

    How to Fix

    • Mark the type parameter [NonCopyable], if the generic is yours. Its body is then checked.
    • Add the member to a symbol list file if it makes no copy and the generic is not yours to mark. The message gives the line to add. See Symbol List. A member that a clones line names, such as CultureInfo.Clone, can have no such line, and the message says so.
    • Avoid the use, if the member copies, as ToArray does.

    Details

    A member of a generic is used with a non-copyable type bound to a type parameter that is not marked, and the member is not on the symbol list. The analyzer assumes that code which cannot see that a type is non-copyable copies it. See Generics That Are Not Marked.

    The symbol list can name the member with for= for other type parameters only. For example, the built-in framework symbol list names the constructor of Dictionary<TKey, TValue> for TValue, so new Dictionary<LockGuard, string>() gets the warning. The warning then says which type parameters the list names the member for, and gives no line to add, since a line of a file can claim less of a member than the framework symbol list, not more.

    A type parameter that is marked in an assembly that was not built with the analyzer counts as not marked, since nothing checked its generic. The message says so, and the fix is then a symbol list entry, or avoiding the use. See Code Not Built With the Analyzer.

    See Also

    These articles explain the rule behind this warning:

    • Marking a Type Parameter - generics that do not copy, and generics that are not marked.
    • Symbol List - symbol list files, and the lines that you will use most.
    • Built-in Framework Symbol List - what the analyzer ships for the framework, and what cannot be on it.

    Didn't add this analyzer yourself? See Why Am I Seeing This?

    © Singulink. All rights reserved.