Saturday, June 25, 2011

Unit tests fail after enabling Code Coverage

If you add an assembly for code coverage analysis and your unit tests start to fail, then it is probably caused by the following exception:

System.Security.SecurityException: Strong name validation failed.

To fix this issue, in Visual Studio, do the following:
  1. Select “Test” > “Edit Test Run Configurations”
  2. Choose the appropriate testrunconfig
  3. Select the “Code Coverage” section.
  4.  Make sure the “Re-signing key file” is populated with the key file used to sign your assembly.

Tuesday, June 7, 2011

Autoformatting an Entire File or Selection in Visual Studio

Have you ever copied and pasted some code from the Internet or maintained legacy code that was poorly formatted? Luckily, Visual Studio has some shortcuts to easily fix the formatting.

To auto format the entire document, press Ctrl + K, Ctrl + D
To auto format a selection or a the current line, press Ctrl + K, Ctrl + F