Today I downloaded FxCop for the first time (yes, I know I should have done this a long time ago). Not bothering to read any documentation, I loaded up my biggest project and hit “Analyze”. I was presented with a daunting 1,800 messages. Perhaps, I thought, I should start smaller. I loaded up my smallest project; a library containing only one class. Only six messages, much better. I fixed two of these issues (specifying ComVisible and minimum security) but, as I found through the documentation, the other messages could safely be ignored.
I then moved on, analyzing one project at a time. Most of the feedback was useful; some of it (like ComVisible) I didn’t care about but fixed any way; and some of it just had to be ignored (for example, the “Avoid calls that box value types” message had to be ignored in several cases).
Some of the messages I got were quite interesting. For example, I got quite a lot of “Specify IFormatProvider” messages. IFormatProvider is something that I’ve always known about, but never bothered to actually understand. Luckily the FxCop help page for this message proved quite informative and useful. Basically, it says that if you do not specify IFormatProvider, you can easily get unexpected results in certain environments.
Most of the messages were simple mistakes, some of which I couldn’t believe I made. There were quite a few spelling errors in my variable/method names, a few bad calls to the ArgumentException constructor (passing a wrong or misspelled argument name), and some other minor but irritating issues.
All in all, my code is way better than before thanks to FxCop. If you still haven’t downloaded it, give it a shot: http://www.gotdotnet.com/team/fxcop/