So, after significant chocolate consumption and much swearing, I have the answer:
We recently inserted a copyright notice at the top of all our source files. It turns out that some of our source files had a byte order mark (U+FEFF) at the start of the file and the notice ended up being inserted ahead of this character.
StyleCop takes offense to the presence of this character and silently ignores the rest of the file.
Given that the character is, correctly, not rendered by the Visual Studio IDE, it took me three days to spot it :(
EDIT (2013.01.14) : I've created a Perl script to remove BOMs from our source files:
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Find;
my @dir = "C:/TopLevelSourceCodeDirectory";
find(\&edits, @dir);
sub edits() {
my $file = $_;
if( (-f $file)
&&
(
($file =~ /.*\.cs$/)
||
($file =~ /.*\.xaml$/)
||
($file =~ /.*\.whatever$/)
)
) {
#Open the file and read in the data
open (my $in, '<', $file) or die "Can't open $file: $!\n";
my @lines = <$in>;
close $in;
#Open same file for writing
open (my $out, '>', $file) or die "Can't open $file: $!\n";
#Walk through lines, putting into $_, and remove BOMs
for ( @lines ) {
s/\xef\xbb\xbf//g;
print $out $_;
}
close $out;
}
}
One final note; I had all manor of issues writing this script because notepad seemed to add BOMs in the middle of my file (which are, of course, invisible) when I pasted certain character strings in (even though those strings didn't originally contain a BOM). Working out why your regex doesn't match when you can't tell that it has an invisible BOM in the middle of the matcher string is not pleasant.