Problem with Resharper Integration and SA1101


Whilst using resharper 5.1 and StyleCop in VS2010 premium, I encountered message:
Warning 27 SA1101: The call to lblFRED must begin with the 'this.' prefix to indicate that the item is a member of the class.

The line concerned is:
      lblFRED.Text = string.Empty;
The Resharper integration did not highlight this line as having an error (lblFRED is a win forms label control).

If I change the line
    this.lastFRED = this.txtFRED.Text;
    lastFRED = this.txtFRED.Text;
then the SA1101 green squiggle appears. The problem does appears even if there are just a few (<20) stylecop issues.

The problem is a bit more involved than I at first thought as I find the rescan all shows the error but a rescan of just the project does not always show it.

file attachments

Closed Aug 1, 2013 at 2:16 PM by andyr
Closing all Resolved items.


professor_k wrote Jan 11, 2012 at 2:30 PM

In my case same behavior happens on development machine, that caused me to fail build already twice. I double checked my configuration and was unable to find differences.
Please fix, as it's really annoying.

andyr wrote May 2, 2012 at 7:58 PM

So. I've been looking at this issue this evening. Its been around a long time and is not a ReSharper addin issue. Its to do with partial types. When you right click on a codepane and run StyleCop all it has to go on is the code in the pane you are currently analysing - it cannot know where the other files constructing this type are. The same code is called as you type if you are using ReSharper. When you do a full re-scan it gets given the Designer files as well. When its got these it can see the fields etc. from there and make the correct assessment of whether it should have this or base. So, in short, I can't see a way to fix it. I'm very tempted to delete the rule completely, as its got all sorts of issues.

Przemyslaw wrote May 3, 2012 at 1:56 PM

Andy, I wouldn't delete it - it works most the time. Maybe this issue will be addressed by Roslyn, when it is out. Then, if StyleCop replaces own parser with Roslyn one, all the pain will go away.

andyr wrote May 3, 2012 at 2:22 PM

Roslyn won't change this unfortunately. I've actually got it working if you have ReSharper installed now but right clicking on a single codepane and running StyleCop will always have the issue.

andyr wrote May 3, 2012 at 3:46 PM

Fixed for ReSharper codepane analysis in 4.7.19 wit changeset bc6e30dc9adf

TATWORTH wrote May 7, 2012 at 5:36 PM

This issue was fixed in the Stylecop release.