All rules
CA2259Usage Enabled by default: As warning

Ensure ThreadStatic is only used with static fields

Ensure ThreadStatic is only used with static fields

Microsoft docs

Description

System.ThreadStaticAttribute, which indicates that the value of a field is unique for each thread, only affects static (Shared in Visual Basic) fields. When applied to instance fields, the attribute has no impact on behavior.

Cause

The System.ThreadStaticAttribute attribute is applied to an instance field.

Example

class C
{
    [ThreadStatic]
    public int number = 404;
}

When to suppress

It's safe to suppress a warning from this rule. However, the [ThreadStatic] attribute is a nop and isn't doing what you intended it to do.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0