'StyleCop warning SA1126:PrefixCallsCorrectly on name of class

I've seen several answers regarding this warning (SA1126:PrefixCallsCorrectly) when using static fields/properties and others just not wanting to use this.. However I'm at a loss in my situation:

public class MyClass
{
    public string Name = nameof(MyClass);
}

this, base, etc. are not applicable. What should I be using? Or should I just keep ignoring the warning?



Solution 1:[1]

There is a workaround:

public class MyClass
{
    public string Name = $"{nameof(MyClass)}";
}

Solution 2:[2]

Just unload the project and edit its .csproj, where you can find the StyleCop targets import line. Something similar to this -

Import Project = "ProgramFiles\MSBuild\StyleCop\v4.7\StyleCop.targets"

And comment this line out. Worked for me !!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ivan Zavyalov
Solution 2 Roee Ben-Ari