August 17, 2012

Debugging Windows Exceptions with Adplus V7


A tool called Adplus can be used on Windows to get more information on unexpected exceptions, hangs and crashes. If one of these has been reported on a production machine then run Adplus in the background, monitoring that process, and check from dump files afterwards. The dump files should include information on that happened just before the exception, crash or hang. The dump files can be opened in Visual Studio or Windbg for example and ran as a debugging session.


There is a new version of Adplus available, Adplus V7, it's an exe where the old was a vbs. Adplus comes with the "Debugging Tools for Windows", google this to find the latest version.


First stop
http://www.codeproject.com/Articles/315536/Adplus-Handling-managed-exceptions

To get a dump on an exe use the -sc switch with adplus (ensure this is the last switch on the command line) and point it to the full path of the exe. If adplus is working it will launch the exe in a separate window, if not then it hasn't found the exe.

To get a dump on a website running in IIS use the -iis switch.

For some brief information on the "differences between a mini and a full dump".


  1. Visual Studio 2010 is the most straight forward debugging tool I've seen to use when debugging dumps. Simply file open the dump file.
  2. Set the symbols path to the pdb location if there is one.
  3. Debug with mixed.
An alternative in Windbg, also provided with the Debugging Tools for Windows. This is not as intuitive.
Note that the sos will need to be loaded before debugging .NET code,

  1. Enter the command in the Windbg command box, the same command that you created the dump with e.g. .loadby sos clr.
  2. To show the stacktrace type !CLRStack -a. Scroll to the top of the list to see the last call in the stack, the objects can be seen here.
  3. To view the object type !do <object address>. 



http://windbg.info/doc/1-common-cmds.html



July 13, 2012

Immutable Objects

Immutable means "can not change". When an object is referred to as Immutable it means the internals cannot be changed i.e. it's member variables.

This is a design choice, where you might wish objects to be passed around as method arguments but you do not want the original object's internal values to change.
Remember that in C# when you pass an object of type Reference Type into a method as an argument, you are actually passing it by reference, meaning the method can change the original objects values.
To protect objects  from this make them immutable.

How:
Objects are made immutable by simply making their internal variable readonly.

January 19, 2012

Dependency Injection IoC



"Dependancy Injection" is a more specific name for and term used "Inversion of Control".

It's all about letting client developers of your code add there own implementations. To do this your code needs to be very loosly coupled (i.e. none of the usual newing up of concrete classes, the code must be written using Interfaces for example) and configurable (e.g. the client developer drops their implementation dll into a location and adds content to a XML configuration file to tell your host app what class to load and instantiate from the dll).

This is a good intro to "Dependancy Injection" http://www.martinfowler.com/articles/injection.html

These are intros to Microsofts "Dependancy Injection" framework, Unity.

https://www106.livemeeting.com/cc/wwe_us/view?cn=guest&id=1032382093&pw=23D44136 with sourcecode at http://unity.codeplex.com/wikipage?title=Webcast%20demos&referringTitle=Home

http://visualstudiomagazine.com/articles/2011/01/27/the-factory-pattern-in-net-part-3.aspx