Wednesday, January 28, 2009

Tracking down boxing

I just found a cool extension, CodeSearch, for Reflector, a disassembler for .NET assemblies.  I used it to search some of our code for the Intermediate Language box instructions and unbox.

I found a lot more of those than I'd hoped.  But in my test cases they all seemed to be necessary.

Wednesday, January 21, 2009

Converting Com ErrorCodes to friendly messages

Using PerfMon to do some .NET profiling today, I wanted the ability to easily retarget my counters at a specific application running on my machine.

Everything went very well except for the error handling.  When adding my counters a  COMException may be thrown.  The Exception's message has the hex error code while the ErrorCode property has the value as an integer. I used the following code to convert the ErrorCode to be comparable against hex values provided by MSDN.

Update, an easier way to do this is comException.ErrorCode.ToString("X");

UInt32 errorCodeLookup = 0;
    errorCodeLookup = (UInt32)comException.ErrorCode;

I didn't end up using this method as it was my own application.  I thought about using a uint enumeration to store all the error codes and then a dictionary to go lookup the user friendly error messages provided by MSDN, but since it is just a scrap app I didn't bother.

Wednesday, January 14, 2009

Identifying Duplicated Code (Refactoring Opportunities)

On our project we have some accidentally similar code and some knowingly similar code.  Today I found a great tool we could easily incorporate into our Continuous Integration Process to stop code duplication.

Simian, a configurable command line utility, took less than 5 minutes to setup and cranked through 204,930 lines of C# in about 6.5 seconds.  The application is free for noncommercial use and can be evaluated free of charge for 15 days.