Friday, June 10, 2011

Helpful tools for the weary programmer Part 1

Hi All,

[beginner level]
Today I am going to talk about some tools which make my life as a programmer somewhat easier. I know there are tons of articles such as this but I want to give my personal view on the way I work. A nice lecture about useful tools was given in the 2010 TechEd in Eilat and can be found here. The tools I am going to talk about are either free or come with the installation of Visual Studio and they are ordered by their usefulness to me and grouped by functionality.

Locating your files
If you are still using windows search function then this tool is for you. The tool is called Everything. (This tool was shown to me by David Elentok couple years back, you can find his blog with very interesting posts on my favorite blogs section on the right side of the page.)
After installing, the tool will "index" your hard drive. I write "index" in double quotes because it doesn't really read  your entire hard drive like some other search tools, it simply reads the NTFS table and maps it to an internal database (which is about 4Mb in size, depends on the size and content of your hard drive). This process runs the first time you start Everything and takes around 1-2 minutes. Every time you start Everything again it will update the local database within several seconds (the default behaviour is to let it start with windows and let it run in the background, then you don't even have to wait for it to start every time)  After the "indexing" is done each search takes... well... it searches as fast as you can type. The search results are updated as soon as you make changes to the files on your hard drive which can be very useful. One problem I found with this tool is that it sometimes doesn't show correct file metadata, this is a minor issue which should be taken into account.
I think this tool is a must for anyone working on a computer.

Who store my referenced dll (or who accessed my file)?
How many times did you get this exception message:
Could not load file or assembly <SomeDllName> implementation version=1.0.0.0, culture=neutral, publickeystoken = 90ba9c70f846762e or one of its dependencies. the system cannot find the specified files.
What do you do then? You open Everything (see previous paragraph) type in <SomeDllName> and of course find this file in your bin directory. This leaves you with one of its dependencies... doh!

As an example I created a console application called LoadExample which is unable to load a dll called MissingDll (because I deleted it... :))

The easiest thing to do is to run "Fusion". Note that it needs to be run as administrator and you need permissions to edit the registry! Just run the tool (find it using Everything on your drive) as administrator (right-click on the executable file and select Run As Administrator) then in the settings set it to log failures and select some (existing) custom path to be able to delete the cache. Run the problematic application and you will see the missing dll.

This is what you see when you run LoadExample with Fusion

There is a missing file but it is not an assembly? You can use the Sysinternals Process Monitor which is downloadable as part of the Sysinternals Suite. Start procmon.exe and set the filter path to either the missing file name or if you don't know the missing file name then set the process name to your application process name (use the "contains" condition so that you don't have to write exact names and paths). Now run the application and check the Results column. You are looking for anything that might be a hint for a problem and usually contains the words "NOT FOUND". Note that the Process Monitors monitors five types of operations as denoted by small icons on the right side of the main toolbar. If you are looking for a missing file you might want to leave only the file system activity turned on.

I found the missing dll

Missing dll in native code (or CLI)? There is a simple solution in the form of Dependency Walker. Once you load a dll in Dependency Walker, it will show all the dlls it depends on in a hierarchical tree. If there are missing dlls they will he highlighted using a special icon. This is especially useful when you fail to register a dll using regsvr32 because it will show all the dlls which are needed (and missing) for the registration.

You can get more (or less) information on this topic by reading this blog post.

Next week I will publish the second part of this post with some more useful tools.
Thanks for reading,
Boris