Saturday, January 29, 2005

Some invaluable utilities every .Net programmer should have

During my time as a C# programmer I have come across the following useful .Net utilities:
(I am a C# programmer so most of the tools would be geared towards programming in C#)

The first thing you need as a .Net programmer is the .Net Framework 1.1 SDK, which you can download for free from Microsoft. This includes the free .Net compiler and other useful tools.
Have a look at: http://msdn.microsoft.com/netframework/
You can download the SDK at
.NET Framework SDK Version 1.1

Probably the most often used tool during programming is the IDE and compiler you use.

IDEs + Compilers:
- I prefer using the Microsoft Development Environment 2003 / Microsoft Visual C# .Net. It has excellent features for development.

- You can also use the COMPLETELY FREE SharpDevelop IDE at www.icsharpcode.net. It can import Microsoft IDE projects.

-Also have a look at CodeSmith, in which you can create code templates to quickly create code for you.
Find it at http://www.ericjsmith.net/codesmith/

Class browsers + decompilers:
- You just HAVE to get the free class browser and .Net decompiler Reflector written by Lutz Roeder at http://www.aisto.com/roeder/dotnet. It can decompile any .Net Assembly to IL (Intermediate language), C#, Visual Basic .Net or Delphi .Net. You can browse the assembly class methods and follow the calls through the call hierarchy as a call or callee graph. This is helpful if you for instance want to know where a certain assembly's class method is used in other assemblies.
He also has a free resource browser and a HTML WYSIWYG editor called WRITER.

- In order to decompile Java .class files (for possible migration to .Net) you can use Atanas Neshkov's DJ Java Decompiler. When I want to migrate an app from Java to .Net I usually decompile the class files using this tool and then use the Java code either directly as C# (since there is much similarity between C# and Java) or you can first compile it using Visual J# and then decompile it to C# using Reflector. Get is at http://members.fortunecity.com/neshkov/dj.html


File comparison Utilities:
- You definitely need Windiff.exe. It is part of the Microsoft Platform SDK available from Microsoft. or look for Windiff.exe on the net

- Another cool source code comparison program is Winmerge.exe. It allows you to selectively choose which part of the code in 2 files you want to merge. Get it at: http://winmerge.sourceforge.net

Both of the above can also compare entire directory paths.


Debugging tools:
- You just have to get the "Debugging tools for Windows" from Microsoft at http://www.microsoft.com/ddk/debugging/. It comes with a debugging extension called SOS (Son of Strike) which can be used to get the method call stack trace from any running .Net assembly (even Release built) and find out exactly in what class method your program is stuck. You attack to any .Net process and you can see all the system threads, .Net managed threads and class and method names. You can also get a heap dump and browse through all the objects on the heap. Run WinDbg.exe. Simply attach to the process. Type .load sos. And then !clrstack : to obtain the common language runtime stack of the thread you picked. (You must have sos.dll in the same directory as WinDbg.exe) . You can also get another version of sos.dll called psscor.dll, which also provide CLR debugging support.
Here is a list of URLs where you can get help on CLR runtime debugging:
A word for WinDbg
Bugslayer SOS It's Not Just an ABBA Song Anymore -- MSDN Magazine, June 2003
Getting proper Stack information from memory dump
More on debugging with SOS.DLL - enter Visual Studio
SOS - Now with 20% More Commands!
SOS Debugging with the CLR
SOS Debugging of the CLR, Part 1
Traversing the gc heap (and introducing PSSCOR.DLL)
You can even set up a symbol path and point it to Microsoft and this app will automatically download all the non-.Net debugging symbols
Simply set:
_NT_SYMBOL_PATH=
SRV*C:\Home\Tools\Development\Debugging Tools for Windows\LocalSymbolCache*http://msdl.microsoft.com/download/symbols
Speed and Memory allocation profilers:
- When you simply have to find that resource leak have a look at this freeware memory profiler:ALLOCATIONPROFILER.EXE which can be found at - http://www.gotdotnet.com
- If your program is stuck in a loop or if you want to find out which method in your app consumes the most of your process time, have a look at NPROF at http://nprof.sourceforge.net/. It launches your app and monitors all method calls allowing you to see exactly what % of time is spent in each class' method.

Windows System tools:
When your apps are misbehaving you must definitely get some of these apps from www.sysinternals.com:
PROCEXP.EXE Process explorer - can show you exactly which processes are running, what thread is taking all your CPU time and then you can match the thread ID up to the threads in WinDbg to see in which method it is looping. You can also see exactly how much memory is in the GC1, GC2 and GC3 garbage collector heaps if you are suspecting a memory leak...Yes a memory leak in .Net
TCPVIEW.EXE Shows you what tcp connections are connected and what processes are listening on ports on your PC
FILEMON.EXE Lets you monitor all file accesses and filter according to process - showing you where apps are trying to hide files on your computer
REGMON.EXE Lets you monitor all registry reads and writes and you can also filter on processes

SPYXX.exe is an app which is part of the Microsoft Platform SDK and it allows you to determine all the windows and windows handles and you can intercept all the windows messages sent to each and every window....very handy in debugging custom controls.
DEPENDS.EXE (Microsoft Dependency walker) is an app which is part of the Microsoft Platform SDK and shows you all the DLL dependencies of an application. You can even see which functions/procs are called in the DLL from the app in question.


Get yourself the above tools. It will open up your knowledge of .Net programming.

No comments: