Hiding your privates from StyleCop

I like StyleCop but I didn’t like the fact it produced warnings on private fields and methods.  I was wrong. Not wrong in that I didn’t like warnings on privates, but wrong that I thought there was no way to tell it to stop it.

Apparently there is.  Jason Allor kindly left a comment saying that it can be configured through the StyleCop settings dialog in Visual Studio.

I took a look and initially didn’t find it.  I didn’t find it because I assumed there’d be different rules for public and private entities.  But there’s not, you can decide at the rule type level:


It’d be nice to have separate rules for public and private.  Currently, I’ve turned off all Documentation rules because I don’t like being warned that I haven’t commented private methods.  However, I’d still like it to give me all the other great warnings if I do decide to comment a particular private method.

Programs that launch (or should launch) Visual Studio

Programs such as FxCop provide links to source files that can be clicked and then edited in Visual Studio. 

FxCop recently (probably since I went 64bit, but also possibly a side-effect of running Windows 7) started failing when clicking these links.  It said:

Could not start Microsoft Visual Studio. Try specifying an alternate source code editor in Application Settings.

Maybe it just looks in Program FilesMicrosoft Visual Studio[whatever version].  Anyway, I couldn’t see anything in the event log or any local FxCop logs, so I just changed the setting under ToolsSettings to use an explicit path to devenv.exe.

This worked, although it started a new instance of the IDE for every file.  To get around that, you need to use the /Edit argument.  Here’s what it looks like (click to make it bigger):


There’s other handy switches, some of which I knew about, like building a particular project/solution (to get the full list, run devenv.exe /?).   It now uses an existing instance of Visual Studio if one’s present, otherwise it starts one up. 

ThoughtWork’s Mingle on X64 machines

By default, 32 bit applications installed on 64 bit machines are installed into the Program Files (x86) directory.

Mingle, in particular, Ruby doesn’t like the brackets in this path, hence, when Mingle tries to start, it fails.  It writes the following entries to the log file in the program’s directory:

Failed to load Rails: C:/Program Files (x86)/Mingle_2_2/app/controllers/caching/keys.rb:1: Invalid char `257’ (‘¯’) in expression C:/Program Files (x86)/Mingle_2_2/vendor/rails/activesupport/lib/active_support/dependencies.rb:505:in `load’ C:/Program Files (x86)/Mingle_2_2/config/../vendor/rails/railties/lib/initializer.rb:475:in `load_application_initializers’ C:/Program Files (x86)/Mingle_2_2/config/../vendor/rails/railties/lib/initializer.rb:474:in `each’ C:/Program Files (x86)/Mingle_2_2/config/../vendor/rails/railties/lib/initializer.rb:474:in `load_application_initializers’ C:/Program Files (x86)/Mingle_2_2/config/../vendor/rails/railties/lib/initializer.rb:145:in `process’ C:/Program Files (x86)/Mingle_2_2/config/../vendor/rails/railties/lib/initializer.rb:93:in `run’ C:/Program Files (x86)/Mingle_2_2/config/environment.rb:116 C:/Program Files (x86)/Mingle_2_2/config/environment.rb:1

The solution: change the default installation to just Program Files.  Handy.  If you want to use Mingle.  On a 64 bit machine.

Problems adding an XBox 360 Media Center Extender

Skip this if you’re not using a Linksys Wireless N device, Media Center, or an XBox 360!

After my umpteenth Seagate disk packed up yesterday, I’ve just reinstalled Windows 7 X64.  I have spent the last couple of hours trying to get an XBox 360 connected to Windows Media Center.

Not too long ago I went through the exact same thing:  Start WMC, Start the XBox,  type the number on the XBox’s screen into WMC, and get nothing.  The last time I did this, it was too late in the day to discover what was wrong or how to fix it – but the next day, everything worked perfectly!

This time, I went through exactly the same ritual.  I looked at the Security event log and it said that :

Event 5032 – Audit Failure – Windows Firewall was unable to notify the user that it blocked an application from accepting incoming connections on the network.

After ensuring that I’d allowed Media Center Extenders through the home network (shortly followed by turning the damn firewall off altogether), I started getting (from the Media Center log under Applications and Services Logs in Event Viewer):

Event 538 – Media Center Extender Setup failed as the Extender was detected on the network but the UPnP search for the Extender failed (timed out after 20000ms).

This all seemed very familiar and nothing I was doing was making a difference.  It was at this point on my last attempt that I went off to do something else.  This time though, the something else’s opening hours hadn’t yet arrived, so I persevered!

In the corner of the screen (remember, this is a fresh install), was the Windows Update icon.  I checked to see what it needed to update, and along with the 294 Office 2007 security patches was an update for a Marvell – Network – Wireless-N USB Network Adapter.  I wondered if this had anything to do with my Linksys Wireless N USB, and it looks like it does.  And after restarting, everything worked great!

The information from Windows Update showed this information:

Marvell – Network – Wireless-N USB Network Adapter

Update type: Optional

DriverUpdate: Marvell Network software update released in October, 2007

More information:


The URL wasn’t much good as it was broken.  The driver information from device manager reads:

Marvell Semiconductor, Inc, version – filename MRVW24C.sys.

This replaced the Vista drivers that I downloaded and installed from the Cisco site.

In fact, I’ve just done a search for Marvell Linksys driver, and it showed this page.  This shows how to force the driver on Vista/Windows 7 if it doesn’t show up via Windows Update.

I hope some of these keywords will help others with this problem.  My heart sank when I searched for the Media Center error and didn’t get 1 single hit!  That shouldn’t happen any more!

Tool update: Visual Studio Orphaned Items


A while back I did a small simple tool to find files on disk that were once part of a Visual Studio project but are now orphaned (removed from the project but still on disk and in your source repository).  I’ve just updated it to find obsolete files from Visual Studio 2008 projects.  You can download the app or the installer, or the source (or all of them!).  The installer adds a right-click context menu action for .csproj files in Windows Explorer.

Available here.


StyleCop is a tool that looks at your source code and recommends ways to improve readability and consistency.  For instance, it tells you to:

  1. Put things in a consistent order in the file – Constructors first, followed by public methods, followed by private methods etc.
  2. Put a blank line after a closing brace.  I thought this was a bit anal, but for some reason it makes code much more readable.  On a related note, some people swear by having no blank lines in their source.  Their reasoning: they can see more on screen without having to scroll and can see more of the method on screen at once.  To me, this was like reading a book with no paragraphs.  Also, If you’ve got methods that take up a whole screen, they’re probably doing too much and are too complex.  I was invited to try it with the reassurance that I’d eventually see the benefit.  I declined, but then realised that I had been ‘trying it’ all along – every time I read the code! 
  3. Remove unnecessary parenthesis.  Reminds of a quote:  “Parenthesis (however relevant) are unnecessary.”
  4. Add XML comments to methods, properties, and events.

There’s hundreds of suggestions, mostly good, although there are some issues – here’s mine:

  1. I generally don’t like to comment private methods, but there doesn’t seem a way to tell it to only warn me if I have public methods that are undocumented.  I hope this’ll be added to the next version.  I don’t like commenting private methods as, if I feel it needs a comment, then the code isn’t self describing and is either a) poorly named, or b) too complex, or c) doing too much.
  2. StyleCop says don’t precede field names with notation.  I follow the almost ubiquitous practice of preceding private fields with an underscore.  For no other reason than to be able to type underscore + ctrl+space and have intellisense pop-up my private fields.  

The good news is that it’s possible to turn off  warnings.  It’s also very well thought out in how these settings are managed:  If you think a certain warning is so ridiculous you never want to see it again, you can put it in the StyleCop.Settings file and put this file at the top of your source tree.  If you’ve got a project where it would make sense to turn off a warning just for that project, you can put another StyleCop.Settings file at the project level.  More here.

I’m wondering if anybody would be brave enough to integrate this in their CI process!  Breaking the build because there’s not a blank line under a brace seems a tad extreme!

C# 4 – Default Parameters

Coming from a C++ background, I’m really pleased that there’ll eventually be default parameters built into the next version of C#. But I do think that C++ had a much cleaner way of handling them: it would only allow defaults from right to left, for instance:

void foo(int a, int b, int c=3, int d=4)

It wouldn’t let you do:

void foo(int a=1, int b=2, int c, int d)

C# will, so for the example above, you’d end up with method calls that could look like:

foo( ,  , 3, 4)

One feature that I still really miss from C++ is const. This keyword could be applied to methods or parameters, so a method declared as:

void foo(int a, int b) const

would be guaranteed to not modify the state of the object (except for mutable members)

A method declared as:

void foo (const Person person)

would be guaranteed to not modify the person.

Maybe C# 5?

Adding folders to the Class View in Visual Studio

I didn’t know this, but you can add folders to the Class View. You can then drag classes to it.   What’s even better, you can drag methods to it!

Thanks to Sara Ford for her post describing this.

There’s more good news! When you’re editing code in the editor and you’re over a class or method, you can use the ‘Synchronise Class View’ command (I’ve mapped mine to a keyboard short-cut, but you can add a toolbar item) to synchronise the Class View to the item you’re currently editing.  Once synchronised, you can go to Class View and drag that into one of your folders.  Also, when you do this, you won’t upset any of your team with changes to the solution or project files – because these are your settings, and hence are stored in the .suo file (which, on the other hand could be a pain, because user option files shouldn’t be checked into your source repository).

Anyway, this is the next best thing to a ‘bread-crumb’ feature in the editor that let’s you jump around to favourite places in the the code.   Maybe the bread-crumb feature will be in the next version of ReSharper?

Displaying values in the Visual Studio Debugger

Normally, when you display values in the Visual Studio debugger, you get formatting (quotes, tabs etc.) included. For instance, if you’ve got string s = "Hello[tab]World"; then hovering over s in the debugger displays "HellotWorld". If you wanted to copy a value value to the clipboard (maybe because you landed on an exception and you want to send the error to the idiot that caused it your fellow colleague), you’d probably right click on the value and select ‘copy value’. This copies the value to the clipboard. Another way is to use the immediate window. Using the example above, typing ‘s’ in the immediate window would produce:


To get rid of formatting (the quotes and the control characters), use the ,nq option:


This is useful in itself, but it really becomes invaluable if you want to show some XML. With the magical ,nq switch, the following code:

produces the following output in the immediate window:

Pretty useless, but if you add ,nq, you get:

Much nicer.

nq stands for nice’n quick, because it doesn’t waste time writing quotes.