Getting a StyleCop SA0102 error with C# 4.0

I’m currently working on my first .NET 4.0 project at work. Whilst I’ve played with .NET 4.0 before, this is the first project where I’ve used it in conjunction with StyleCop. All was fine at first, then I suddenly started getting the following error when trying to build:

SA0102: A syntax error has been discovered in file XXX on line YYY.

Rather than relating to a StyleCop rule, this indicates that StyleCop has encountered an issue which it is unable to deal with i.e. you have no way of simply suppressing the error and moving on.

Turns out we were still using StyleCop 4.3 which does not support all of the new C# 4.0 syntax – in my case it was choking on the use of named parameters. It clearly didn’t like the colon syntax introduced into call sites.

After upgrading to v4.4 the problem went away although there are a couple of side effects to bear in mind:

1) Depending on your build configuration and where you store the StyleCop binaries, you may need to edit your Visual Studio project files to point to the new version.

2) After upgrading (without changing any of the rules) and rebuilding I got a load of SA1009 spacing errors. These were easy enough to fix up, but I’m not entirely sure why this happened unless some default rule changed without my knowing.

This entry was posted in Coding and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Leave a Reply