<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>The SoftSource Community</title><link>http://blogs.sftsrc.com/MainFeed.aspx</link><description>The collected thoughts of NERDS</description><generator>Subtext Version 1.9.5.0</generator><item><title>WinDbg Extension sos2.dll v1.2 released</title><link>http://blogs.sftsrc.com/prashant/archive/2008/11/17/WinDbg-Extension-sos2.dll-v1.2-released.aspx</link><pubDate>Tue, 18 Nov 2008 10:28:03 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/prashant/archive/2008/11/17/WinDbg-Extension-sos2.dll-v1.2-released.aspx</guid><wfw:comment>http://blogs.sftsrc.com/prashant/comments/115.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/prashant/comments/commentRss/115.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/prashant/archive/2008/11/17/WinDbg-Extension-sos2.dll-v1.2-released.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/prashant/services/trackbacks/115.aspx</trackback:ping><source url="http://blogs.sftsrc.com/prashant/rss.aspx">WinDbg Extension sos2.dll v1.2 released</source><description>&lt;style type="text/css"&gt;&lt;!--
		A:link { so-language: zxx }
	--&gt;&lt;/style&gt;
&lt;p&gt;Version 1.2 supports a command to dump GC Handles by type. Actually,  support for this command was suggested by &lt;a style="FONT-WEIGHT: bold" href="http://resharper.blogspot.com/"&gt;Ilya Ryzhenkov&lt;/a&gt; (ReSharper Product Manager at JetBrains) . &lt;br /&gt;
&lt;/p&gt;
&lt;p style="COLOR: rgb(0,0,255)"&gt;&lt;strong&gt;&lt;a href="http://debuggingblog.com/resources/sos2.zip"&gt;Download it from here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To Do List is to dump all the handles for a type along with stats with an option to specify the # of handles. For example, if there are 100 strong gchandles, you may want to print just 10 of them or so&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&lt;u&gt;&lt;strong&gt;GCHandlesByType(gcht)&lt;/strong&gt;&lt;/u&gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;br /&gt;
&lt;br /&gt;
————————————————&lt;br /&gt;
Get GC Handles Stat by Type&lt;br /&gt;
————————————————&lt;br /&gt;
!GCHandlesByType provides statistics about GCHandles by type.&lt;br /&gt;
Supported Types are&lt;br /&gt;
1. Pinned(p)&lt;br /&gt;
2. AsyncPinned(ap)&lt;br /&gt;
3. Strong(s)&lt;br /&gt;
4. WeakLong(wl)&lt;br /&gt;
5. WeakShort(ws)&lt;br /&gt;
6. RefCount(r)&lt;br /&gt;
&lt;/font&gt;&lt;strong&gt;&lt;font color="#000000"&gt;Example Syntax&lt;/font&gt;&lt;/strong&gt;&lt;font color="#000000"&gt;&lt;br /&gt;
&lt;/font&gt;&lt;font color="#000000"&gt;&lt;u&gt;!gcht -t &amp;lt;type&amp;gt;&lt;/u&gt;&lt;/font&gt;&lt;font color="#000000"&gt;&lt;br /&gt;
type specified is not case sensitive, for example command syntax to print the&lt;br /&gt;
stat for Strong handle type is&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;0:003&amp;gt; !gcht -t strong&lt;br /&gt;
||&lt;br /&gt;
0:003&amp;gt; !gcht -t s&lt;br /&gt;
||&lt;br /&gt;
0:003&amp;gt; !gcht -t Strong&lt;br /&gt;
Strong GC Handle Statistics:&lt;br /&gt;
Strong Handles: 15&lt;br /&gt;
Statistics:&lt;br /&gt;
      MT    Count    TotalSize Class Name&lt;br /&gt;
793040bc        1           16 System.Object[]&lt;br /&gt;
79330fb8        1           28 System.SharedStatics&lt;br /&gt;
79331e38        2           48 System.Reflection.Assembly&lt;br /&gt;
79330ec0        1           56 System.Threading.Thread&lt;br /&gt;
79330c30        1           72 System.ExecutionEngineException&lt;br /&gt;
79330ba0        1           72 System.StackOverflowException&lt;br /&gt;
79330b10        1           72 System.OutOfMemoryException&lt;br /&gt;
793310cc        1          100 System.AppDomain&lt;br /&gt;
793325b0        4          144 System.Security.PermissionSet&lt;br /&gt;
79330cc0        2          144 System.Threading.ThreadAbortException&lt;br /&gt;
Total 15 objects&lt;br /&gt;
&lt;br /&gt;
&lt;/font&gt;&lt;/p&gt;
&lt;p style="COLOR: rgb(0,0,255)"&gt;&lt;strong&gt;&lt;a href="http://debuggingblog.com/resources/sos2.zip"&gt;Download it from here&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/prashant/aggbug/115.aspx" width="1" height="1" /&gt;</description><dc:creator>Prashant</dc:creator></item><item><title>ADPlus configuration file to the rescue</title><link>http://blogs.sftsrc.com/prashant/archive/2008/11/13/ADPlus-configuration-file-to-the-rescue.aspx</link><pubDate>Fri, 14 Nov 2008 05:43:57 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/prashant/archive/2008/11/13/ADPlus-configuration-file-to-the-rescue.aspx</guid><wfw:comment>http://blogs.sftsrc.com/prashant/comments/114.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/prashant/comments/commentRss/114.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/prashant/archive/2008/11/13/ADPlus-configuration-file-to-the-rescue.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.sftsrc.com/prashant/services/trackbacks/114.aspx</trackback:ping><source url="http://blogs.sftsrc.com/prashant/rss.aspx">ADPlus configuration file to the rescue</source><description>&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; FONT-WEIGHT: bold; mso-outline-level: 1"&gt;ADPlus Configuration file to the rescue&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Someone asked me about getting a memory dump on breakpoints in production environment. &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Usually, you won't have the luxury of attaching a debugger and inserting a breakpoint in production environment. However, you can still get a memory dump under different conditions or execute a command line option using ADPlus configuration file. AdPlus does support -hang switch to take a memory dump of a process anytime but that's not good enough if you need to take a memory dump on a particular first chance exception or even when a breakpoint is hit. &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;ADPlus script supports configuration file with -c switch to create a memory dump of a user mode win32 process. You should read more on ADPlus configuration file on WinDbg help.&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; FONT-WEIGHT: bold; mso-outline-level: 1"&gt;Below is the example of a ADPlus configuration file, which will create a memory dump under the following conditions&lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in; unicode-bidi: embed; DIRECTION: ltr; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in" type="1"&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Verdana; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="1"&gt;&lt;span style="COLOR: blue"&gt;When the application throws an unhandled exception with the exception code 0x80000001, a guard page exception which occurs when you access for example a stack's guard page.&lt;/span&gt;&lt;/li&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Verdana; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="2"&gt;&lt;span style="COLOR: maroon"&gt;Creates a full dump, when breakpoint hits the function kernel32.dll!UnhandledExceptionFilter&lt;/span&gt;&lt;/li&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Verdana; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="3"&gt;&lt;span style="COLOR: blue"&gt;Creates a mini dump. When breakpoint hits the function&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;kernel32.dll!SetUnhandledExceptionFilter&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;ADPlus&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;&amp;lt;!-- RunMode could be crash or hang, Quiet suppresses the warning message box--&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;Settings&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;RunMode&amp;gt; CRASH &amp;lt;/RunMode&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Option&amp;gt; Quiet &amp;lt;/Option&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;ProcessName&amp;gt; &amp;lt;process name&amp;gt;&amp;lt;!--e.g. cmd.exe--&amp;gt; &amp;lt;/ProcessName&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;/Settings&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;&amp;lt;!--&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;PreCommands is included to change the symbol path for kernel32.dll, the first command .sympath sets the symbol path to c:\windows\system32(kernel32.dll location and the 2nd command reload the kernel32.dll defaulting to export symbols.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;The reason for loading the export symbols has to do with setting a breakpoint in kernel32.dll functions as described in my last blog entry&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;--&amp;gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;PreCommands&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Cmd&amp;gt; .sympath c:\windows\system32 &amp;lt;/Cmd&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Cmd&amp;gt; .reload /f kernel32.dll &amp;lt;/Cmd&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;/PreCommands&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;Exceptions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Config&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Code&amp;gt;0x80000001&amp;lt;/Code&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Actions1&amp;gt;&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;MiniDump &amp;lt;/Actions1&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;Actions2&amp;gt;&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;FullDump &amp;lt;/Actions2&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;/Config&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;/Exceptions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;Breakpoints&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;NewBP&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Type&amp;gt; BM &amp;lt;/Type&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Address&amp;gt; kernel32.dll!UnhandledExceptionFilter &amp;lt;/Address&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Actions&amp;gt; FullDump&amp;lt;/Actions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;CustomActions&amp;gt; r &amp;lt;/CustomActions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;/NewBP&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;NewBP&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Type&amp;gt; BM &amp;lt;/Type&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Address&amp;gt; kernel32.dll!SetUnhandledExceptionFilter &amp;lt;/Address&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;Actions&amp;gt; MiniDump &amp;lt;/Actions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt;&amp;lt;CustomActions&amp;gt; r &amp;lt;/CustomActions&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 0.5in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 2"&gt;&amp;lt;/NewBP&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in 0in 0in 1in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 3"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;/Breakpoints&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&amp;lt;/ADPlus&amp;gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Below is the command line snapshot to run adplus configuration file with "exception.cfg"&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;img width="412" height="68" alt="" src="/images/blogs_sftsrc_com/prashant/commandline_adplus.jpg" /&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/prashant/aggbug/114.aspx" width="1" height="1" /&gt;</description><dc:creator>Prashant</dc:creator></item><item><title>Breakpoint gotcha with kernel32.dll microsoft public symbols</title><link>http://blogs.sftsrc.com/prashant/archive/2008/11/12/Breakpoint-gotcha-with-kernel32-public-symbols.aspx</link><pubDate>Thu, 13 Nov 2008 07:10:51 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/prashant/archive/2008/11/12/Breakpoint-gotcha-with-kernel32-public-symbols.aspx</guid><wfw:comment>http://blogs.sftsrc.com/prashant/comments/113.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/prashant/comments/commentRss/113.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/prashant/archive/2008/11/12/Breakpoint-gotcha-with-kernel32-public-symbols.aspx#comment</comments><slash:comments>1</slash:comments><trackback:ping>http://blogs.sftsrc.com/prashant/services/trackbacks/113.aspx</trackback:ping><source url="http://blogs.sftsrc.com/prashant/rss.aspx">Breakpoint gotcha with kernel32.dll microsoft public symbols</source><description>&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;While debugging crash dump generation issue as described in my previous blog on Dr Watson gotcha, I noticed that you can't set a breakpoint on kernerl32 functions since microsoft symbols server gives you access to stripped public symbols only. This is one of those scenario where you would rather have export symbols.&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-DECORATION: underline; mso-outline-level: 1"&gt;Scenario&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;While doing live debugging or attaching a debugger to generate a dump when it hits a breakpoint on kernel32!SetUnhandledExceptionFilter&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-DECORATION: underline; mso-outline-level: 1"&gt;Steps using WinDbg&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Run the following command&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Calibri; FONT-SIZE: 11pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; COLOR: blue; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;0:021&amp;gt; bm kernel32!SetUnhandledExceptionFilter&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;You can use bm to set a symbol breakpoint that matches the pattern. &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-DECORATION: underline; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; FONT-WEIGHT: bold; TEXT-DECORATION: underline; mso-outline-level: 1"&gt;Gotcha&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;If you have symbol server path set correctly pointing to microsoft public symbol server, WinDbg will display the following message and it suggest you to switch to export symbols&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;No matching code symbols found, no breakpoints set.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;&lt;span style="BACKGROUND: yellow; mso-highlight: yellow"&gt;If you are using public symbols, switch to full or export symbols.&lt;/span&gt;&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; FONT-WEIGHT: bold; mso-outline-level: 1"&gt;How to Switch to Export Symbols to set a breakpoint?&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Verdana; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Run the following commands&lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in; unicode-bidi: embed; DIRECTION: ltr; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in" type="1"&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Arial; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="1"&gt;&lt;span style="COLOR: blue"&gt;0:000&amp;gt; .sympath c:\windows\system32&lt;/span&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; COLOR: blue; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Symbol search path is: c:\windows\system32&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; TEXT-DECORATION: underline; mso-outline-level: 1"&gt;This will set your symbol path to kernel32.dll which should be under your windows system folder in my case it is "c:\windows\system32"&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in; unicode-bidi: embed; DIRECTION: ltr; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in" type="1"&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Arial; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="2"&gt;&lt;span style="COLOR: blue"&gt;0:000&amp;gt; .reload /f kernel32.dll&lt;/span&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; COLOR: blue; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;*** ERROR: Symbol file could not be found.&lt;span style="mso-spacerun: yes"&gt;  &lt;/span&gt;Defaulted to export symbols for C:\Windows\system32\kernel32.dll - &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;Don't worry about ERROR message because this is what we want, we want it be set to export symbols. .reload command will reload the symbols for kernerl32.dll defaulting to export symbols&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;ol style="MARGIN-TOP: 0in; unicode-bidi: embed; DIRECTION: ltr; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in" type="1"&gt;
    &lt;li style="MARGIN-TOP: 0px; FONT-FAMILY: Arial; MARGIN-BOTTOM: 0px; FONT-SIZE: 10pt; VERTICAL-ALIGN: middle; mso-outline-level: 1" value="3"&gt;&lt;span style="COLOR: blue"&gt;0:000&amp;gt; bm kernel32!SetUnhandledExceptionFilter&lt;/span&gt; &lt;/li&gt;
&lt;/ol&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; COLOR: blue; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;breakpoint 6 redefined&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; COLOR: blue; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;6: 7617d16f @!"kernel32!SetUnhandledExceptionFilter"&lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt; &lt;/p&gt;
&lt;p style="MARGIN: 0in; FONT-FAMILY: Arial; FONT-SIZE: 10pt; mso-outline-level: 1"&gt;And your breakpoint is set using export symbols and of course you can use depends for all the exported symbols.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/prashant/aggbug/113.aspx" width="1" height="1" /&gt;</description><dc:creator>Prashant</dc:creator></item><item><title>Debugging Rules</title><link>http://blogs.sftsrc.com/prashant/archive/2008/11/11/Debugging-Rules.aspx</link><pubDate>Wed, 12 Nov 2008 11:02:25 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/prashant/archive/2008/11/11/Debugging-Rules.aspx</guid><wfw:comment>http://blogs.sftsrc.com/prashant/comments/112.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/prashant/comments/commentRss/112.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/prashant/archive/2008/11/11/Debugging-Rules.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/prashant/services/trackbacks/112.aspx</trackback:ping><source url="http://blogs.sftsrc.com/prashant/rss.aspx">Debugging Rules</source><description>Check out this book from David Agans on Debugging Rules (&lt;a href="http://www.debuggingrules.com"&gt;http://www.debuggingrules.com&lt;/a&gt;) Below is the must have poster for all Debuggers &lt;img alt="Debugging Rules poster" src="http://www.debuggingblog.com/debuggingrules.jpg" /&gt;&lt;img src="http://blogs.sftsrc.com/prashant/aggbug/112.aspx" width="1" height="1" /&gt;</description><dc:creator>Prashant</dc:creator></item><item><title>we were done with dr watson or so you thought</title><link>http://blogs.sftsrc.com/prashant/archive/2008/11/10/drwatson.aspx</link><pubDate>Mon, 10 Nov 2008 12:30:07 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/prashant/archive/2008/11/10/drwatson.aspx</guid><wfw:comment>http://blogs.sftsrc.com/prashant/comments/111.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/prashant/comments/commentRss/111.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/prashant/archive/2008/11/10/drwatson.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/prashant/services/trackbacks/111.aspx</trackback:ping><source url="http://blogs.sftsrc.com/prashant/rss.aspx">we were done with dr watson or so you thought</source><description>&lt;p&gt;&lt;strong&gt;&lt;u&gt;Scenario&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;cdb debugger(using adplus script) fails to create a crash dump although application is terminating unexpectedly. First thought, may be stack corruption.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Steps to resolution&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1) Get a mini dump when it hits a breakpoint &lt;strong&gt;kernel32!UnhandledExceptionFilter&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;2) Get a mini dump when it hits a breakpoint &lt;strong&gt;kernel32!SetUnhandledExceptionFilter&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt; Surprise&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1) 002eebb4 6dcbc89f &lt;strong&gt;&lt;font color="#ff0000"&gt;00000000&lt;/font&gt;&lt;/strong&gt; 0040f7f0 c0000417 kernel32!SetUnhandledExceptionFilter 002eeeec 6dc802fd 00000000 00000000 00000000 msvcr90&lt;strong&gt;!_invoke_watson&lt;/strong&gt;+0xec &lt;/p&gt;
&lt;p&gt;2) 002eebb4 6dcbc8ac 002eec14 0040f7f0 c0000417 kernel32!UnhandledExceptionFilter 002eeeec 6dc802fd 00000000 00000000 00000000 msvcr90&lt;strong&gt;!_invoke_watson&lt;/strong&gt;+0xf9&lt;/p&gt;
&lt;p&gt; It turns out CRT - C runtime library is hardcoded to use Dr Watson. You will notice that &lt;strong&gt;SetUnahdledExceptionFilter&lt;/strong&gt; is called with NULL so basically it is deleting any unhandled exception filter.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Following is the stack trace&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;002eebb4 6dcbc8ac 002eec14 0040f7f0 c0000417 kernel32!UnhandledExceptionFilter&lt;br /&gt;
002eeeec 6dc802fd 00000000 00000000 00000000 msvcr90!_invoke_watson+0xf9&lt;br /&gt;
002eef34 6dc80366 045b0030 ffffffff 00000001 &lt;strong&gt;msvcr90!fread_s&lt;/strong&gt;+0x4a&lt;br /&gt;
002eef50 6ef3105e 045b0030 00000001 000001f4 &lt;strong&gt;msvcr90!fread&lt;/strong&gt;+0x18&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Root Cause Analysis&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1) Crash dump was not getting created because it was using fread with invalid runtime parameter resulting in calling hardcoded dr watson&lt;/p&gt;
&lt;p&gt;2) Event log also shows the &lt;font size="2"&gt; &lt;/font&gt;Exception Code = 0xC0000417, defined as #define STATUS_INVALID_CRUNTIME_PARAMETER ((NTSTATUS)0xC0000417L) in "NTSTATUS.h" &lt;/p&gt;
&lt;p&gt;prior to windows vista, DrWatson is installed as the default post mortem debugger. But you always have an option to set WinDbg or NTSD or any other debugger to change post mortem debugger. However, you don't have Dr Watson in Windows Vista ( now you have windows error reporting service). So, We ran into an interesting issue while trying to get a crash dump for a user mode win32 process. &lt;/p&gt;
&lt;p&gt;&lt;strong&gt;More Information&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;After googling on _invoke_watson, got more information on it from microsoft&lt;/p&gt;
&lt;p&gt;&lt;font face="Arial"&gt;&lt;a href="http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=101337"&gt;&lt;font color="#ff0000"&gt;A proposal to make Dr.Watson invocation configurable&lt;/font&gt;&lt;/a&gt;&lt;/font&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/prashant/aggbug/111.aspx" width="1" height="1" /&gt;</description><dc:creator>Prashant</dc:creator></item><item><title>Ruby on Rails Setup with DreamHost</title><link>http://blogs.sftsrc.com/stuart/archive/2008/10/28/109.aspx</link><pubDate>Tue, 28 Oct 2008 13:29:21 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/10/28/109.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/109.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/109.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/10/28/109.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/109.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Ruby on Rails Setup with DreamHost</source><description>&lt;p&gt;As step 1 of &lt;a target="_blank" mce_href="http://stuartthompsontech.wordpress.com/2008/10/27/the-aspnet-silverlight-php-rails-experiment/" href="http://stuartthompsontech.wordpress.com/2008/10/27/the-aspnet-silverlight-php-rails-experiment/"&gt;my latest experiment&lt;/a&gt;, I've started by configuring a &lt;a target="_blank" mce_href="http://www.rubyonrails.org" href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt; site with &lt;a target="_blank" mce_href="http://www.dreamhost.com" href="http://www.dreamhost.com/"&gt;DreamHost&lt;/a&gt;.  This actually involved quite a bit of setup work, which is not unusual when remotely hosting a new website.  I have documented the steps as fully as I can for anyone else curious about trying development in Rails.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1 - Signup with DreamHost&lt;/strong&gt;&lt;br /&gt;
You can sign up &lt;a target="_blank" mce_href="http://www.dreamhost.com/r.cgi?461119" href="http://www.dreamhost.com/r.cgi?461119"&gt;using this link&lt;/a&gt; or use the promo code LETMETRYRAILS and receive $50 off (i.e. no setup fee).&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 2 - Configure your domain&lt;/strong&gt;&lt;br /&gt;
The next step is to configure your domain.   We'll start at the &lt;a target="_blank" mce_href="http://panel.dreamhost.com" href="http://panel.dreamhost.com/"&gt;DreamHost configuration panel&lt;/a&gt;.  Select &lt;em&gt;Domains&lt;/em&gt; and then &lt;em&gt;Manage Domains&lt;/em&gt; from the left-hand sidebar.  This will bring up the list of domains in your account.  Click the &lt;em&gt;Edit &lt;/em&gt;button in the &lt;em&gt;Web Hosting&lt;/em&gt; column.&lt;/p&gt;
&lt;p&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_managedomains2.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_managedomains2.jpg"&gt;&lt;img height="228" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_managedomains2.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_managedomains2.jpg" title="dreamhost_managedomains2" class="alignnone size-full wp-image-62" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This will open the settings page for that domain.  Check the FastCGI and Passenger (mod_rails) checkboxes.  Finally click the &lt;em&gt;Change fully hosted settings now!&lt;/em&gt; button (note that this button is not at the bottom of the page, rather at the end of the first section).&lt;/p&gt;
&lt;p&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_configuredomain1.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_configuredomain1.jpg"&gt;&lt;img height="366" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_configuredomain1.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_configuredomain1.jpg" title="dreamhost_configuredomain1" class="alignnone size-full wp-image-63" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;FastCGI support allows your Rails project to run much faster.  The Passenger (mod_rails) option allows your Rails application to be configured much more easily and is the &lt;a target="_blank" mce_href="http://wiki.dreamhost.com/Passenger" href="http://wiki.dreamhost.com/Passenger"&gt;preferred DreamHost method&lt;/a&gt; for hosting Ruby on Rails applications.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 3 - Configure your FTP/SSH user&lt;/strong&gt;&lt;br /&gt;
We will be performing much of the setup and configuration of the website via SSH.  We will need to setup a user account for this purpose.  During your initial setup you should have created an ftp account for your domain, probably with the same name as that domain (if you accepted the defaults).  Select the &lt;em&gt;Users&lt;/em&gt; and then &lt;em&gt;Manage Users&lt;/em&gt; options from the left side-bar.  Click the &lt;em&gt;Edit&lt;/em&gt; button next to your user in the &lt;em&gt;Actions &lt;/em&gt;column.&lt;/p&gt;
&lt;p&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_editusers.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_editusers.jpg"&gt;&lt;img height="216" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_editusers.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_editusers.jpg" title="dreamhost_editusers" class="alignnone size-full wp-image-61" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This will open the following page where you can edit your user.  Change the User &lt;em&gt;Account Type&lt;/em&gt; to &lt;em&gt;Shell account&lt;/em&gt; and select the &lt;em&gt;/bin/bash&lt;/em&gt; shell type.  Finally, hit the &lt;em&gt;Save Changes&lt;/em&gt; button at the bottom of the page.&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_editingftpuser.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/dreamhost_editingftpuser.jpg"&gt;&lt;img height="297" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_editingftpuser.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/dreamhost_editingftpuser.jpg" title="dreamhost_editingftpuser" class="alignnone size-full wp-image-64" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;This enables the user to connect using a Telnet/SSH client, which is exactly what we are going to do next.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 4 - Download some tools&lt;/strong&gt;&lt;br /&gt;
Next we're going to download the tools we'll need to create and configure our rails website.  We'll need the latest release of Ruby, MySQL, HeidiSql, and PuTTY.  HeidiSql is a free gui for maintaining MySQL databases.  PuTTY is a free Telnet/SSH client that we'll use for remote configuration of our site.  Note that you do not need to signup on the MySQL site to get the download.  Click the &lt;em&gt;No thanks, just let me download&lt;/em&gt; link.&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Ruby 1.8.6-27 RC1 can be &lt;a target="_blank" mce_href="http://rubyforge.org/frs/?group_id=167" href="http://rubyforge.org/frs/?group_id=167"&gt;downloaded here&lt;/a&gt;.&lt;/li&gt;
    &lt;li&gt;MySQL 5.0 Community Server can be &lt;a target="_blank" mce_href="http://dev.mysql.com/downloads/mysql/5.0.html#win32" href="http://dev.mysql.com/downloads/mysql/5.0.html#win32"&gt;downloaded here&lt;/a&gt; (select the Windows ZIP/Setup.EXE (x86) option)&lt;/li&gt;
    &lt;li&gt;HeidiSQL 3.2 can be &lt;a target="_blank" mce_href="http://www.heidisql.com/download.php" href="http://www.heidisql.com/download.php"&gt;downloaded here&lt;/a&gt;.&lt;/li&gt;
    &lt;li&gt;PuTTY can be &lt;a target="_blank" mce_href="http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html" href="http://www.chiark.greenend.org.uk/%7Esgtatham/putty/download.html"&gt;downloaded here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 5 - Installing Rails&lt;/strong&gt;&lt;br /&gt;
Now that we have the necessary tools installed it is time to setup Rails locally.  Fortunately, Ruby comes with everything we need to get setup and running, including the WEBrick web server that we can use to run and test our site before deployment.  When installing Ruby, be sure to check the &lt;em&gt;Enable RubyGems &lt;/em&gt;option on the first page of the installer.&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rubyinstallation.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rubyinstallation.jpg"&gt;&lt;img height="355" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rubyinstallation.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rubyinstallation.jpg" title="rubyinstallation" class="alignnone size-full wp-image-66" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;Once the installer completes, open up a command window and execute the following commands:&lt;/p&gt;
&lt;p mce_style="text-align:left;padding-left:30px;" style="text-align: left; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd ruby/bin&lt;br /&gt;
gem update --system&lt;br /&gt;
gem install rails --version 2.1.2&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This will use the gem system to install rails locally.  If everything is successful, your command window should look something like this:&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/installrails1.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/installrails1.jpg"&gt;&lt;img height="294" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/installrails1.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/installrails1.jpg" title="installrails1" class="alignnone size-full wp-image-69" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;You may need to restart your system at this point.  Ughh.  This is because Windows Vista and XP sometimes struggle to detect that new environment variables were added to the $PATH.  Unless you relish fully qualifying the &lt;em&gt;C:/Ruby/bin&lt;/em&gt; directory on the next few commands, I'd advise you restart now.  It's also not a bad idea since we did just install four new programs.  I've found Windows seems to run more smoothly if you reboot after installing new things.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 6 - Create your Rails site locally&lt;/strong&gt;&lt;br /&gt;
Now that we have Rails setup, let's create a simple site locally.  I created a new directory on C:\ called &lt;em&gt;projects&lt;/em&gt; in which to develop the site.  Open a command prompt and type the following:&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd \&lt;br /&gt;
md projects&lt;br /&gt;
cd projects&lt;br /&gt;
rails MyRailsSite&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This will create your rails site in &lt;em&gt;C:\projects\MyRailsSite&lt;/em&gt;.  Before we add our first view and controller, let's quickly check that everything wired up properly.  To do this we need to start the WEBrick server:&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd C:\projects\MyRailsSite&lt;br /&gt;
ruby script/server&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Vista may ask if you wish to &lt;em&gt;unblock&lt;/em&gt; Ruby, which you do.  Your command prompt should look something like the following:&lt;/p&gt;
&lt;p&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_webrickserver.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_webrickserver.jpg"&gt;&lt;img height="141" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_webrickserver.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_webrickserver.jpg" title="rails_webrickserver" class="alignnone size-full wp-image-71" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can now navigate to &lt;a target="_blank" mce_href="http://127.0.0.1:3000" href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000&lt;/a&gt; to see your site.  If everything is configured correctly you should see the Ruby on Rails welcome page:&lt;/p&gt;
&lt;p&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rubyonrails_welcomescreen.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rubyonrails_welcomescreen.jpg"&gt;&lt;img height="336" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rubyonrails_welcomescreen.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rubyonrails_welcomescreen.jpg" title="rubyonrails_welcomescreen" class="alignnone size-full wp-image-72" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We can shutdown the WEBrick server by pressing Ctrl-C in the command prompt window.&lt;/p&gt;
&lt;p&gt;Now let's create our first controller and view.  We're going to keep it simple and put up a page that displays the message "Hello World!".  At the command prompt type the following:&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd projects\MyRailsSite&lt;br /&gt;
ruby script/generate controller HelloWorld&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_createcontroller.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_createcontroller.jpg"&gt;&lt;img height="167" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_createcontroller.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_createcontroller.jpg" title="rails_createcontroller" class="alignnone size-full wp-image-73" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This will generate a new controller for you as well as a new view.  If you aren't familiar with MVC development, just follow along for now until the sample becomes clear.  The rest will come in time and with additional reading and practice.  For now it is suffice to say that a controller will perform the work for a web page request where the view will display the results of that work.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Let's edit the controller that was generated.  To do this, open up an explorer window, navigate to &lt;em&gt;C:\projects\MyRailsSite\app\controllers&lt;/em&gt;, right-click over the &lt;em&gt;hello_world_controller.rb&lt;/em&gt; file and select &lt;em&gt;Edit&lt;/em&gt; from the context menu.  This should open the controller file in the SciTE editor.  We need to add lines to the class to respond to the &lt;em&gt;index&lt;/em&gt; action.  The &lt;em&gt;index&lt;/em&gt; action is the default action that will be performed for a controller.  To do this, edit the file to look like the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_editcontroller.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_editcontroller.jpg"&gt;&lt;img height="186" width="442" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_editcontroller.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_editcontroller.jpg" title="rails_editcontroller" class="alignnone size-full wp-image-74" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This &lt;em&gt;controller&lt;/em&gt; will now set the variable &lt;em&gt;@message&lt;/em&gt; to the literal "Hello World"; when the index &lt;em&gt;action&lt;/em&gt; is requested.  Controllers perform actions.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Save the file and close it.  Now we will create a view to display the message.  Navigate to the &lt;em&gt;C:\projects\MyRailsSite\app\views\hello_world&lt;/em&gt; directory in explorer (notice how Rails created the view directory for us).  Right-click in the directory and create a new file called &lt;em&gt;index.html.erb&lt;/em&gt;.  Now right-click this file and open it in your favorite editor (Notepad will suffice).  Add the following to the file:&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_createview.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_createview.jpg"&gt;&lt;img height="194" width="347" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_createview.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_createview.jpg" title="rails_createview" class="alignnone size-full wp-image-75" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Save the file and close the editor.  We're almost ready to test out our new controller and view.  First, however, we need to configure a &lt;em&gt;route&lt;/em&gt; for our site.  A &lt;em&gt;route&lt;/em&gt; is a mapping from an end-point (url) in our site to an actual controller and view that will fulfil the request.  In explorer, navigate to &lt;em&gt;C:\projects\MyRailsSite\config&lt;/em&gt;, right-click the file &lt;em&gt;routes.rb&lt;/em&gt; and select &lt;em&gt;Edit&lt;/em&gt; from the context-menu.  This will open your routes file in the SciTE editor.  Almost the entire file is commented out.  Most of this file contains instructions for configuring custom routes.  We're going to comment out the last two lines of the file and insert a single mapped route of our own.  Edit the end of the file to look like the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_editroutes.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_editroutes.jpg"&gt;&lt;img height="105" width="460" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_editroutes.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_editroutes.jpg" title="rails_editroutes" class="alignnone size-full wp-image-76" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This line connects the &lt;em&gt;helloworld&lt;/em&gt; route to the &lt;em&gt;hello_world&lt;/em&gt; controller for the &lt;em&gt;index&lt;/em&gt; action.  The action specification isn't actually necessary as the index action is assumed by default if none is specified, but I prefer to be explicit.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;There is one final thing we'll need to do before we can browse to our page locally.  We need to install and configure MySQL.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 7 - Install and configure MySQL&lt;/strong&gt;&lt;br /&gt;
This is a very short step.  Run the MySQL setup package you downloaded earlier and select the &lt;em&gt;Typical&lt;/em&gt; installation option.  Then hit Next-&amp;gt;Next-&amp;gt;Finish all the way to the end.  When the configuration wizard runs, choose &lt;em&gt;Detailed Configuration&lt;/em&gt;, then &lt;em&gt;Developer Machine, &lt;/em&gt;then&lt;em&gt; &lt;/em&gt;&lt;em&gt;Multifunctional Database&lt;/em&gt;.  When asked for a location for the Inno files, I used &lt;em&gt;C:\projects\MySQL&lt;/em&gt;.  Choose &lt;em&gt;Decision Support (DSS)/OLAP&lt;/em&gt; then leave both boxes checked on the next dialog with 3306 as the port number.  Choose &lt;em&gt;Standard Character Set&lt;/em&gt;, then check &lt;em&gt;Install As Windows Service&lt;/em&gt; and leave &lt;em&gt;Include Bin Directory in Windows PATH&lt;/em&gt; unchecked.  Enter a new root password, leave &lt;em&gt;Create An Anonymous Account&lt;/em&gt; unchecked.  Finally, hit &lt;em&gt;Execute&lt;/em&gt; to finish the configuration wizard.  MySQL is now installed and configured.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 8 - Create a database for our project&lt;/strong&gt;&lt;br /&gt;
We'll need to create a database for our project.  To do this we'll need to install HeidiSql.  Let's run that installer now.  I use the defaults from the installer except on the &lt;em&gt;Select Additional Tasks&lt;/em&gt; dialog where I uncheck &lt;em&gt;Associate .SQL Files with HeidiSQL. &lt;/em&gt;When the installer completes it will launch the HeidiSQL gui.  Click the New button at the top of the first dialog.  Name the connection &lt;em&gt;MyRailsSite&lt;/em&gt;, click OK, and then enter the password you selected during your MySQL installation into the password box provided.  The first thing we're going to do is create a new database.  Right-click over root@127.0.0.1 in the left side-bar and select &lt;em&gt;Create database&lt;/em&gt; from the context menu.  Enter &lt;em&gt;MyRailsSite&lt;/em&gt; as the database name and click ok.  Now select Tools-&amp;gt;User-Manager from the top menu.  We're going to create a new user to avoid using the root user in our application.  For the &lt;em&gt;Username&lt;/em&gt; type myrailsdbuser, set&lt;em&gt; From Host &lt;/em&gt;to&lt;em&gt; localhost&lt;/em&gt;, and type a password for your new user.  Don't use the same password you used for root.  In the &lt;em&gt;Allow access to&lt;/em&gt; list, left-click over the &lt;em&gt;myrailssite&lt;/em&gt; database (it will turn yellow).  Now click &lt;em&gt;Add User&lt;/em&gt;.  Then click &lt;em&gt;Close&lt;/em&gt; to close the user manager dialog.  Now we've created a database and a specific user for our Rails application to use.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 9 - Configure Rails to use the database&lt;/strong&gt;&lt;br /&gt;
Finally we need to configure our Rails site to use our new database.  In an Explorer window, navigate to &lt;em&gt;C:\projects\MyRailsSite\config&lt;/em&gt;, right-click the &lt;em&gt;database.yml&lt;/em&gt; file and edit it in your favorite editor (I use &lt;a target="_blank" mce_href="http://www.textpad.com/" href="http://www.textpad.com/"&gt;TextPad&lt;/a&gt; but NotePad will suffice).  Edit your file to look like the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_dbconfig2.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_dbconfig2.jpg"&gt;&lt;img height="380" width="285" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_dbconfig2.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_dbconfig2.jpg" title="rails_dbconfig2" class="alignnone size-full wp-image-83" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt; &lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt; &lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 10 - Testing the site locally&lt;/strong&gt;&lt;br /&gt;
We're finally ready to test the site locally!  Open up a command window are run the following to start the WEBrick server:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd c:\projects\myrailssite&lt;br /&gt;
ruby script/server&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Then open a browser and navigate to &lt;a target="_blank" mce_href="http://127.0.0.1:3000/" href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000/&lt;/a&gt;.  You'll notice that the Rails welcome page still displays.  However, change the url in the browser to point to &lt;a target="_blank" mce_href="http://127.0.0.1:3000/helloworld" href="http://127.0.0.1:3000/helloworld"&gt;http://127.0.0.1:3000/helloworld&lt;/a&gt;.  You should now see your view displaying the message "Hello World!".  Let's remove the default index page now and then make your default route point to your &lt;em&gt;helloworld&lt;/em&gt; view.  To do this, open up Explorer and navigate to &lt;em&gt;c:\projects\myrailssite\public&lt;/em&gt;.  This is your site's public directory.  From here, delete the &lt;em&gt;index.html&lt;/em&gt; file.  That's the welcome page gone; we don't need it anymore.  Now navigate to &lt;em&gt;c:\projects\myrailssite\config&lt;/em&gt; and open the &lt;em&gt;routes.rb&lt;/em&gt; file again.  Add the following line just before the map.connect line we added earlier:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;map.root :controller=&amp;gt;"hello_world"&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This configures the &lt;em&gt;root&lt;/em&gt; route to point to our hello world controller.  As we stated earlier, there is no need to specify the &lt;em&gt;index&lt;/em&gt; action as it is assumed by default.  Save and close the file, then browse to &lt;a target="_blank" mce_href="http://127.0.0.1:3000" href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000&lt;/a&gt; once more.  Your site should now be displaying your "Hello World!" message.  Note how the url is just &lt;a target="_blank" mce_href="http://127.0.0.1:3000" href="http://127.0.0.1:3000/"&gt;http://127.0.0.1:3000&lt;/a&gt; and doesn't have helloworld at the end.  This is an important point about routes.  You aren't navigating a particular directory structure on the site, you are simply navigating routes and actions.  The controller could be named anything you like as long as the route for a particular end-point correctly routed requests for that end-point to your controller.  For now, let's stop the WEBrick server and close the command window.  The final task is to get your Rails site up to &lt;a mce_href="http://www.dreamhost.com" href="http://www.dreamhost.com/"&gt;DreamHost&lt;/a&gt; and serve your "Hello World!" request remotely.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 11 - Configuring DreamHost for your site&lt;/strong&gt;&lt;br /&gt;
This final configuration step may seem a little confusing at first, but only if you aren't familiar with Linux and BASH.  It doesn't take very long and it isn't important to understand how it works because you'll only need to do it once.  We're going to install version 2.1.2 of rails to your remote host because that's the version that Passenger (mod_rails) needs in order to run your site.  This is where we'll need PuTTY.  Fortunately there is no installation step with PuTTY.  It is simply an executable that you download and run.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;When you run PuTTY, you will need to supply the username and password of the user we configured in step 3.  This will connect you to the server that will host your site.  The following instructions are commands to enter into the BASH shell as well as instructions on editing your ~/.bash_profile file (which is similar to environment settings for the command shell in Windows).  The first part of these instructions is about editing your ~/.bash_profile file to ensure that some paths and other required settings are configured before beginning installation.  These instructions have been adapted from the &lt;a target="_blank" mce_href="http://wiki.dreamhost.com/RubyGems" href="http://wiki.dreamhost.com/RubyGems"&gt;DreamHost wiki article on this topic&lt;/a&gt;.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Before we update rails, let's first create our Rails site remotely.  To do this, first run PuTTY.  For the &lt;em&gt;Host Name&lt;/em&gt; you will supply your domain name in the form www.MyDomainName.com.  Then click &lt;em&gt;Open&lt;/em&gt;.  I choose &lt;em&gt;No&lt;/em&gt; from the next dialog as I don't want to store anything in the registry.  You will now enter the username and password for the user we created in step 3.  When you connect, type &lt;em&gt;ls&lt;/em&gt; and hit enter.  This is the BASH command to list the contents of the current directory.  You should see &lt;em&gt;MyDomainName.com&lt;/em&gt; listed in the output.  We are going to navigate to that folder and then create a rails site inside that folder.&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd MyDomainName.com&lt;br /&gt;
rails MyRailsSite&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This will create a Rails site on the DreamHost server, the same way we did it locally earlier.  We're going to create the site like this and then upload our site files from our local machine to the remote site.  To upload our files, we'll use an Explorer window and ftp.  First, however, we need to create a copy of our database.yml and environment.rb files.  This is because those files will be different on our remote host than they are locally.  Create a copy of each of those files called database.yml.live and environment.rb.live now.  Now edit the database.yml.live file to look like the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;a mce_href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_dbconfiglive2.jpg" href="http://stuartthompsontech.files.wordpress.com/2008/10/rails_dbconfiglive2.jpg"&gt;&lt;img height="134" width="281" alt="" mce_src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_dbconfiglive2.jpg" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails_dbconfiglive2.jpg" title="rails_dbconfiglive2" class="alignnone size-full wp-image-87" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt; &lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Edit your environment.rb.live file and uncomment the following line (its on line 5):&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;ENV['RAILS_ENV'] ||= 'production'&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;This is important because running in development mode under FastCGI will cause memory leaks on the DreamHost server.  They will catch them and clean them up but it's better to run in full production mode and not cause problems.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;One final change we need to make locally is to update the &lt;em&gt;c:\projects\myrailssite\config\environments\production.rb&lt;/em&gt; file.  Comment out the &lt;em&gt;config.action_view.cache_template_loading = true&lt;/em&gt; line as it causes problems with the Passenger product that will host our site.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Now we're ready to install Rails 2.1.2 remotely.  Switch back to your PuTTY session (or log in again if you &lt;em&gt;exit&lt;/em&gt;ed).  Let's first edit the ~/.bash_profile file.  To do this we will be using the &lt;em&gt;nano&lt;/em&gt; text editor.  To open the ~/.bash_profile file in nano, type the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;nano ~/.bash_profile&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Now you can use the cursor keys to navigate the file.  We need to add the following lines to the end of the file:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;# Path settings&lt;br /&gt;
export GEM_HOME="$HOME/.gems"&lt;br /&gt;
export GEM_PATH="$GEM_HOME:/usr/lib/ruby/gems/1.8"&lt;br /&gt;
export PATH="$HOME/bin:$HOME/.gems/bin:$PATH"&lt;br /&gt;
export RUBYLIB="$HOME/lib:$RUBYLIB"&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;# Stops the DreamHost processes from killing the gem install process&lt;br /&gt;
alias gem="nice -n19 ~/bin/gem"&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;To save your changes press Ctrl-O then hit enter.  Press Ctrl-X to exit the editor and return to the shell.  You can now type &lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cat ~/.bash_profile&lt;/span&gt; and the contents of the file should be printed out.  This is a good way to check that your changes were saved and that you typed everything correctly.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Now we need to perform the installation.  The following commands will achieve this:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd ~&lt;br /&gt;
mkdir .gems&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;mkdir bin lib src&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd ~/src&lt;br /&gt;
wget http://rubyforge.org/frs/download.php/43985/rubygems-1.3.0.tgz&lt;br /&gt;
tar xzvf rubygems-1.3.0.tgz&lt;br /&gt;
cd rubygems-1.3.0&lt;br /&gt;
ruby setup.rb --prefix=$HOME&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="padding-left:30px;" style="padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd ~/bin&lt;br /&gt;
ln -s gem1.8 gem&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;For more information on what each of these steps is doing check the &lt;a target="_blank" mce_href="http://wiki.dreamhost.com/RubyGems" href="http://wiki.dreamhost.com/RubyGems"&gt;DreamHost wiki article&lt;/a&gt;.  We can check that the path and gem versions are correct by typing the following:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;which gem&lt;br /&gt;
gem -v&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;These commands should return &lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;/home/USERNAME/bin/gem&lt;/span&gt; and &lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;1.3.0&lt;/span&gt; respectively.  Now we can execute the command to install Rails 2.1.2, which is:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;gem install rails --version 2.1.2&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;What we've accomplished here is to install RubyGems and Rails 2.1.2 to our hosted server.  The last thing we need to do to make everything work is to use rake to &lt;em&gt;freeze&lt;/em&gt; our version of Rails to 2.1.2 so that Passenger will use our Rails installation when running our site.  The commands to do this are as follows.  Please note that you need to supply your domain name in the format MyDomainName.com and the name of your Rails site in place of MyRailsSite in the first command.  This simply changes the current directory so that we're running rake in the right place.&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;cd ~/MyDomainName.com/MyRailsSite/&lt;br /&gt;
rake rails:freeze:edge TAG=rel_2-1-2&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;That's it!  Phew.  That felt like a lot of work, but at least you only have to do it once.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;&lt;strong&gt;Step 12 - Deploying and testing your site remotely&lt;/strong&gt;&lt;br /&gt;
Now that we've set up the environment with &lt;a target="_blank" mce_href="http://www.dreamhost.com" href="http://www.dreamhost.com/"&gt;DreamHost&lt;/a&gt;, the only task left is to deploy the site remotely and test it out.  Before we do that though, we are going to check one last configuration setting in the DreamHost control panel, just to be sure that everything is setup correctly.  If you navigate to Domains-&amp;gt;Manage Domains in the left side-bar and then click the &lt;em&gt;Edit&lt;/em&gt; button again (see step 2), then check out the &lt;em&gt;Specify your web directory&lt;/em&gt; setting.  This is where &lt;a target="_blank" mce_href="http://www.dreamhost.com" href="http://www.dreamhost.com/"&gt;DreamHost&lt;/a&gt; will send requests to &lt;em&gt;MyDomainName.com&lt;/em&gt;.  It should be set to:&lt;/p&gt;
&lt;p mce_style="text-align:justify;padding-left:30px;" style="text-align: justify; padding-left: 30px;"&gt;&lt;span mce_style="color:#000080;" style="color: rgb(0, 0, 128);"&gt;/home/username/MyDomainName.com/MyRailsSite/public&lt;/span&gt;&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;By setting the directory to the &lt;em&gt;public&lt;/em&gt; directory of your Rails site, it means that users cannot navigate outside of that directory and browse places that they aren't supposed to be.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Let's finish up and deploy our Rails site from the local machine to the remote server.  We'll use Explorer and ftp to do this.  Open up Explorer and type &lt;em&gt;ftp://ftp.MyDomainName.com&lt;/em&gt; into the address bar.  Now open up the &lt;em&gt;MyDomainName.com&lt;/em&gt; and then &lt;em&gt;MyRailsSite&lt;/em&gt; folders.  You will need to copy your app directory from your local machine at &lt;em&gt;c:\projects\myrrailssite\app&lt;/em&gt; up to the remote server.  When you have copied these files, navigate to the &lt;em&gt;pubilc &lt;/em&gt;directory on the remote server and delete the index.html file.  We don't need the Rails welcome page on live anymore either!  Then navigate to the &lt;em&gt;config&lt;/em&gt; directory and copy the &lt;em&gt;routes.rb&lt;/em&gt;, &lt;em&gt;environment.rb.live&lt;/em&gt; and &lt;em&gt;database.yml.live&lt;/em&gt; files up to the corresponding folder on the server.  Don't forget to rename these to &lt;em&gt;environment.rb&lt;/em&gt; and &lt;em&gt;database.yml&lt;/em&gt; on the remote server.  We only renamed them so that we could have two different files locally.  Finally, navigate to the &lt;em&gt;config/environments&lt;/em&gt; folder and copy the &lt;em&gt;production.rb&lt;/em&gt; file that we edited up to the corresponding location on the remote server.  From now on, when you deploy your site, you will only have to copy the &lt;em&gt;app&lt;/em&gt; folder to the remote server (unless you change config settings that is).&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;The final step before we can test our site on live is to setup the MySQL database on the DreamHost side to match the one we set up locally.  Since we didn't create any database tables, this is fairly simple to do through the DreamHost interface.  Go to Goodies-&amp;gt;Manage MySQL and repeat the same steps here as we did in step 8.  You can also use HeidiSQL if you want to manage your database remotely that way.  However, for now I recommend using the DreamHost web interface to do this work.  All you need to ensure is that the database name and username/password for that database match the settings you specified in your database.yml file.  I'm going to cover using databases in Rails in more detail in a future article.  For now we just need to get an empty database and a user that has access to keep Rails happy.&lt;/p&gt;
&lt;p mce_style="text-align:left;" style="text-align: left;"&gt;Congratulations!  Assuming that everything was wired up correctly, you should now be able to open a browser and navigate to &lt;em&gt;http://www.MyDomainName.com&lt;/em&gt; to see your site being hosted remotely.&lt;/p&gt;
&lt;p mce_style="text-align:justify;" style="text-align: justify;"&gt;Hopefully this article will help you get up and running with a basic Rails site that is hosted remotely.  The focus of this article was understanding the relationship between running a Rails site locally and hosting it on a remote server.  Setting up your development in this way from day one will save a lot of headaches later when it comes to deployment time.  Developing and testing locally, then deploying to a live host means that problems can be identified early and that changes can be tested locally rather than on a live site.  I'm going to expand upon this article as part of my ongoing experiement with ASP.NET, Silverlight, PHP, and Ruby on Rails.  Next we're going to develop a database, understand models using ActiveRecord, and dig a little deeper into Rails.  For now: happy hosting!&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/109.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>The ASP.NET, Silverlight, PHP, Rails Experiment</title><link>http://blogs.sftsrc.com/stuart/archive/2008/10/27/108.aspx</link><pubDate>Mon, 27 Oct 2008 11:06:37 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/10/27/108.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/108.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/108.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/10/27/108.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/108.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">The ASP.NET, Silverlight, PHP, Rails Experiment</source><description>&lt;p style="text-align: justify;"&gt;I've been working with &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/default.aspx"&gt;Microsoft technologies&lt;/a&gt; for over ten years, specifically &lt;a target="_blank" href="http://www.asp.net/"&gt;Microsoft's web development technologies&lt;/a&gt;.  During that time I have built a variety sites ranging in scope from e-commerce, educational, service provision, &lt;a target="_blank" href="http://en.wikipedia.org/wiki/Software_as_a_Service"&gt;SaaS&lt;/a&gt;, to dashboards, portals, internal tools, and even SAP-migration.  While I praise the technology stack for what it allows me to do, it also comes with a whole host of limitations that make it hard for me to deliver the experience my clients would like.  Throughout this decade of web development I have heard a lot from those around me about alternative technology stacks that promise all manner of improvements and experiences.  Unfortunately there is a lot of resistance from any one technology stack to listen to and learn from the stacks around them, most of the cross-platform feedback comes in the form of "Microsoft sucks" or "PHP is for fan-boy script kiddies".  The truth is that a large number of successful business are hosted on a wide variety of platforms.  Each technology stack has to at least be viable for that to be true.  The problem is getting at the truth without the zealous noise of "my stacks better than your stack" getting in the way.&lt;/p&gt;
&lt;p style="text-align: justify;"&gt;I decided that it was time for me to branch out and become more informed on these technologies myself so that I could truly understand the differences and what made each of them unique.  I'm hoping that as part of this experience I can not only become a better developer but also learn the problems that Ruby on Rails or PHP addresses.  I'll like to be able to speak from an informed standpoint about the differences between the Microsoft and open-source approaches as well as better understand the problems each of those development worlds faces on a daily basis.  Either way, it's going to be a heck of a lot of fun.&lt;/p&gt;
&lt;p style="text-align: justify;"&gt;The experiment I have in mind is to build the same web-site using four different technologies.  From the Microsoft camp I have chosen &lt;a target="_blank" href="http://www.asp.net"&gt;ASP.NET&lt;/a&gt; and &lt;a target="_blank" href="http://silverlight.net/"&gt;Silverlight&lt;/a&gt;.  From the open-source perspective I have chosen &lt;a target="_blank" href="http://www.php.net/"&gt;PHP&lt;/a&gt; and &lt;a target="_blank" href="http://www.rubyonrails.org/"&gt;Ruby on Rails&lt;/a&gt;.  I chose PHP and RoR because they are two technologies that I have always wanted to learn.  Learning both of those will also require some digging into &lt;a target="_blank" href="http://httpd.apache.org/"&gt;Apache&lt;/a&gt; and &lt;a target="_blank" href="http://www.linux.org"&gt;Linux&lt;/a&gt;, another two areas that I have too little direct experience with to effectively participate in an informed conversation.&lt;/p&gt;
&lt;p style="text-align: center;"&gt;&lt;a href="http://www.asp.net"&gt;&lt;img height="44" width="108" alt="" src="http://stuartthompsontech.wordpress.com/files/2008/10/logo.png" title="ASP.NET" class="alignnone size-full wp-image-48" /&gt; &lt;/a&gt; &lt;a href="http://www.silverlight.net"&gt;&lt;img height="45" width="131" alt="" src="http://stuartthompsontech.wordpress.com/files/2008/10/silverlightlogo.jpg" title="silverlightlogo" class="alignnone size-full wp-image-49" /&gt; &lt;/a&gt;&lt;a href="http://www.php.net"&gt;&lt;img height="49" width="86" alt="" src="http://stuartthompsontech.wordpress.com/files/2008/10/php.gif" title="php" class="alignnone size-full wp-image-50" /&gt; &lt;/a&gt;&lt;a href="http://www.rubyonrails.org"&gt;&lt;img height="54" width="42" alt="" src="http://stuartthompsontech.wordpress.com/files/2008/10/rails.png?w=74" title="rails" class="alignnone size-thumbnail wp-image-51" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p style="text-align: justify;"&gt;Our horses are ready to race.  In terms of hosting, I have selected &lt;a target="_blank" href="http://www.dreamhost.com"&gt;DreamHost&lt;/a&gt; for the PHP and Rails sites, and I'm going to use &lt;a target="_blank" href="http://www.stormhosts.com"&gt;StormHosts&lt;/a&gt; for the &lt;a target="_blank" href="http://www.asp.net"&gt;ASP.NET&lt;/a&gt; and &lt;a target="_blank" href="http://www.silverlight.net"&gt;Silverlight&lt;/a&gt; projects (assuming that SH can do .NET 3.5, which I believe I saw at some point).  The reason I'm using remote hosting services for this experiment is that I don't believe you get the true experience of a technology stack until you host it in this way.  It is very easy to get a Rails site up and running using &lt;a target="_blank" href="http://www.webrick.org"&gt;WEBrick&lt;/a&gt; and a local installation of Ruby.  Similarly, it is easy to get an ASP.NET site running on the personal web server that ships with &lt;a target="_blank" href="http://msdn.microsoft.com/en-us/vstudio/default.aspx"&gt;Visual Studio 2008&lt;/a&gt;.&lt;/p&gt;
&lt;p style="text-align: justify;"&gt;The first phase of the experiment is to get a "Hello World!" site up and running for each of the four environments.  The specifications are that a single end-point be accessible that displays the text "Hello World!" and that this end-point is accessible in both &lt;a target="_blank" href="http://www.microsoft.com/windows/products/winfamily/ie/default.mspx"&gt;Internet Explorer&lt;/a&gt; 7 and &lt;a target="_blank" href="http://www.mozilla.com/en-US/firefox/"&gt;FireFox&lt;/a&gt; 3.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/108.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>Reflector to go to RedGate</title><link>http://blogs.sftsrc.com/stuart/archive/2008/08/20/107.aspx</link><pubDate>Wed, 20 Aug 2008 07:21:13 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/08/20/107.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/107.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/107.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/08/20/107.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/107.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Reflector to go to RedGate</source><description>&lt;p&gt;
Lutz Roeder has decided to move on from Reflector.  &lt;a href="http://www.red-gate.com/index.htm?gclid=CNj46_jonJUCFRhhnAod-Cqrfw"&gt;RedGate&lt;/a&gt; will be taking over the project from now on.  Fortunately, they have agreed to maintain the &lt;i&gt;community&lt;/i&gt; edition of the software.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blog.lutzroeder.com/2008/08/future-of-net-reflector.html"&gt;http://blog.lutzroeder.com/2008/08/future-of-net-reflector.html&lt;/a&gt;
&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/107.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>NDepend Part II - Beginning CQL</title><link>http://blogs.sftsrc.com/stuart/archive/2008/08/19/106.aspx</link><pubDate>Tue, 19 Aug 2008 09:25:12 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/08/19/106.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/106.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/106.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/08/19/106.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/106.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">NDepend Part II - Beginning CQL</source><description>&lt;p&gt; In my continuing use of &lt;a href="http://www.ndepend.com"&gt;NDepend&lt;/a&gt; on both my work and home projects, I have been investigating CQL more and more, especially from the perspective of use in continuous integration.  NDepend provides some incredibly powerful analysis features and I find the idea that constraints can be applied and warnings reported as part of day 1 builds to be extremely appealing.  I'm all about keeping code clean, constrained, and consistent.  NDepend provides another great tool in my kit to ensure that my own code is marshalled to my standards from the very first line that is written.  As David Muhondro put so eloquently in his blog post, NDepend is &lt;a href="http://www.mohundro.com/blog/2008/03/26/NDependStaticAnalysisOnSteroids.aspx"&gt;static analysis on steroids&lt;/a&gt;.  When most users encounter CQL for the first time, the response is "wow, this looks really powerful, now what does it mean?".  I've started by taking the stock queries that are included in a basic NDepend project and understanding what they mean and the warnings that they are expected to generate.  By understanding the warnings and their purpose in the project, I began to understand how I could tweak those queries and even write my own to enforce the rules I'd like my code to live by. &lt;/p&gt;
&lt;p&gt; Let's start by looking at an example.  After creating a new NDepend project and pointing it at a list of assemblies to analyze, the default CQL queries that are included are grouped into the following categories: &lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;Code Quality&lt;/li&gt;
    &lt;li&gt;Design&lt;/li&gt;
    &lt;li&gt;Unused Code / Dead Code&lt;/li&gt;
    &lt;li&gt;Encapsulation&lt;/li&gt;
    &lt;li&gt;Diff / Changes / Evolution&lt;/li&gt;
    &lt;li&gt;Test Coverage&lt;/li&gt;
    &lt;li&gt;Purity / Immutability / Side-Effects&lt;/li&gt;
    &lt;li&gt;Naming Conventions&lt;/li&gt;
    &lt;li&gt;.NET Framework Usage&lt;/li&gt;
    &lt;li&gt;Statistics&lt;/li&gt;
    &lt;li&gt;Samples of Custom Constraints&lt;/li&gt;
    &lt;li&gt;Constraints extracted from Source Code&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;a href="http://www.stuartthompson.net/SubTextBlog/Images/stuartthompson_net/SubTextBlog/08-19-2008-DefaultCQLQueries/08-19-2008-DefaultCQLQueries.JPG"&gt;&lt;img border="0" src="http://www.stuartthompson.net/SubTextBlog/Images/stuartthompson_net/SubTextBlog/08-19-2008-DefaultCQLQueries/08-19-2008-DefaultCQLQueries_Thumbnail.JPG" alt="" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt; I started by looking at the &lt;em&gt;Unused Code / Dead Code&lt;/em&gt; queries, specifically at the &lt;em&gt;Potentially unused methods&lt;/em&gt; query.  By double-clicking on the query it is opened in the CQL query editor and displays the following: &lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;div style="border: medium none rgb(136, 136, 136); padding: 3px; background-color: rgb(255, 255, 221); font-family: Courier Sans MS;"&gt; // &amp;lt;Name&amp;gt;Potentially unused methods&amp;lt;/Name&amp;gt;&lt;br /&gt;
WARN IF Count &amp;gt; 0 IN SELECT TOP 10 METHODS WHERE&lt;br /&gt;
MethodCa == 0 AND            // Ca=0 -&amp;gt; No Afferent Coupling -&amp;gt; The method is not used in the context of this application.&lt;br /&gt;
!IsPublic AND                // Public methods might be used by client applications of your assemblies.&lt;br /&gt;
!IsEntryPoint AND            // Main() method is not used by-design.&lt;br /&gt;
!IsExplicitInterfaceImpl AND // The IL code never explicitely calls explicit interface methods implementation.&lt;br /&gt;
!IsClassConstructor AND      // The IL code never explicitely calls class constructors.&lt;br /&gt;
!IsFinalizer                 // The IL code never explicitely calls finalizers.&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt; &lt;strong&gt;Breaking it Down&lt;/strong&gt;&lt;br /&gt;
Let's break this down a little.  First of all it is important to realize that this is not SQL, despite any similarities in the syntax.  The first line selects the top 10 methods that satisfy the query and then raises a warning if the total number of methods is greater than 0.  The reason for the seemingly superfluous top 10 selection is that if the count is greater than zero then those top 10 will be displayed as the results of the query.  To avoid swamping with noise the query is restricting to only the first ten offenders.  The next line is the first part of the WHERE clause and looks for methods with an &lt;a ccnet="" display="" confluence.public.thoughtworks.org="" http:="" href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET"&gt;CruiseControl&lt;/a&gt; to bring these warning and reports into the daily life of your projects.  While static analysis en masse isn't for everyone (not even for me), a small list of CQL queries can help you perform necessary housekeeping without having to do the hard hunting work yourself.  The inevitable question is whether or not this overlaps with FxCop.  There is some overlap, but they are both just tools from which you should pluck the best of the functionality you like and strike down the cruft that gets in the way.  There are some cases where writing an FxCop rule specific to your application is a good thing, however I'm finding that writing CQL queries for warnings lends itself a little better to how I think about static analysis in the first place.  The key is finding that sweet spot in the middle. &lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/106.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>Designing for Testability</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/30/105.aspx</link><pubDate>Wed, 30 Jul 2008 10:56:41 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/30/105.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/105.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/105.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/30/105.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/105.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Designing for Testability</source><description>&lt;p&gt;Automotive manufactures have long been on the vaunted TDD bandwagon.  For years they have harnessed the amazing potential of unit testing, verifying components individually prior to the expensive and time-consuming exercise of assembling them to make a completed vehicle.  Integration testing in the automotive world is very expensive and to find that a single component failure has wasted a fleet of test vehicles as well as many months of construction and fabrication is close to unacceptable.  However, they have also long faced the question of when and where to design for testability; a line still not clearly defined in any industry.&lt;/p&gt;
&lt;p&gt;It makes perfect sense that if a component is to be tested in isolation from the system it will eventually be integrated with that a certain amount of planning is necessary in order to facilitate that testing.  This means that certain designs, while technically and functionally brilliant, may need to be modified if they are ever to be tested.  The question is where to draw the line.  All too often in software engineering the line is drawn firmly on one side or the other, rarely in a position of balance.&lt;/p&gt;
&lt;p&gt;I can understand on a modern motor vehicle with multiple on-board computers performing a variety of related tasks that there is a need to interface with and test those computers thoroughly.  I'm sure that to the component manufacturers the need for extra diagnostic access ports and programmable interfaces is a hindrance to their development; after all they are working in a very closed system.  However, to the test engineers the ability to simulate all manner of failures and receive highly detailed information about everything the computer is doing is absolutely indispensible.  They cannot guarantee the component functions correctly without it.&lt;/p&gt;
&lt;p&gt;Unfortunately this desire for components to be testable can easily get out of hand.  Consider that a test engineer is tasked with ensuring that the onboard computer functions at various speeds.  Unforuntately his equipment is bulky and doesn't fit inside the vehicle.  Even at low speeds he finds that keeping up with a car in motion requires him to run alongside pretty quickly.  Should he require that the car not go faster than 8mph in order to ensure that he can completely guarantee the functionality of the computer for the legal range of speeds he is able to test?  Something tells me that the manufacturer wouldn't be able to sell too many of that particular model.&lt;/p&gt;
&lt;p&gt;Instead the test engineer must find other ways to test the car at high speeds.  Custom models of the car are constructed that allow a connected rig to be tethered to the car, carrying all of the the test equipment alongside even at high speeds.  At even higher speeds, motion simulations and car treadmills are employed to allow for testing that the tethered rig is unsafe for.  The design of the car wasn't limited to a maximum speed of 8mph, rather a compromise was found to allow the right balance of functionality and testing.&lt;/p&gt;
&lt;p&gt;In software engineering, we have a variety of tools and frameworks at our disposal to accomplish similar testing of software.  Unit testing frameworks, mock frameworks, dependency injection containers; they are tools.  Each plays a specific role and solves a particular flavor of problem, however none of them are all-encompassing and all of them require thought before use.&lt;/p&gt;
&lt;p&gt;There is a growing epidemic of code grown out of the desire for "high coverage" unit testing.  However, some of the motivations behind this testing appear to have taken an 8mph turn somewhere; for the worse.  In an effort to improve code quality, the initiatives towards testing have started to build 8mph cars with 6 wheels and no doors.  In terms of test coverage the cars are truly superb, but from the outside many consumers are left scratching their heads and wondering where it all went wrong.&lt;/p&gt;
&lt;p&gt;I usually find that if a particular design decision is inhibiting the testability of a component, one of three things is happening:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The design is so tightly coupled and stable that no testing could hope to penetrate the darkness of the black box surrounding it.  (i.e. a dll with one 5,000 line method inside that does "something")&lt;/li&gt;
&lt;li&gt;The design is so abstract that is doesn't actually do anything.  (i.e. a dll containing only interfaces - test that suckas!)&lt;/li&gt;
&lt;li&gt;The testing tool being applied is the wrong one for the job.&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;As a software engineer, I can fix 1 and 2.  Fortunately with good design and architecture we can actually prevent 1 and 2 from ever reaching QA in the first place.&lt;/p&gt;
&lt;p&gt;There isn't much I can do about number 3.  This is where I ask for the line to be moved a little with regards to the tool that is being employed.  Here are a few examples of hammering screws and screwing nails.&lt;/p&gt;
&lt;p&gt;Static methods, unless invoked through reflection, attract coupling from consumers.  That is to say that if an assembly contains a static method, there is a good chance that something calling that static method has a strong reference to the assembly that exposes it.  This is not a bad thing and there are many places where such a design makes perfect sense.  However, in certain situations, this can cause mocking frameworks to perform more work than necessary to set up the premise for a unit test because they can't mock away the reference the exposed assembly that performs work.  This is because mocking frameworks are ideal for mocking abstract implementations and poor for mocking tightly coupled components.  There is nothing to mock because everything is explicitly stated.  See screw, swing hammer.  Static methods are perfect for unit testing thanks to the magic of reflection.  Inspect the method contract (the logical contract not the physical source code - i.e. what, in English, does it do) and based upon that contract construct a suite of tests to affirm that the method is indeed doing what it promised it would.&lt;/p&gt;
&lt;p&gt;Service assemblies, such as configuration loaders or proxies, tend to operate more upon interfaces than implementations.  That is because the value they add is an operation upon some implementation of an interface rather than a concrete process defined up front.  This is the provider model.  We write a set of interfaces describing the kinds of things a provider can do.  We also write a set of services than help those providers achieve some work.  We don't write the actual providers themselves because this is a plugin model.  Well, how do we test a provider that hasn't been written yet?  Wait, this could be hard in unit testing.  We call a method on an interface but have no way to know what the "as yet unwritten" provider will do in that method call and have no way of knowing whether the result is correct.  NTemporalDisplacementUnit 1.0 hasn't been released yet so we can't do it in a state of temporal flux either...panic!  But wait, in thinking about the problem further we realise that we don't care what the provider does.  The contract we are providing is that we will interact with a provider in a predictable and documented fashion.  As long as we interact with the interface in the correct way and at the correct time, our part of the contract is fulfilled.  Woohoo!  That's what a mock framework is for.  We mock up a provider and check that our service correctly interacts with the provider.  Mock frameworks are great for this.  Finally, a nail that we can hit with our hammer.&lt;/p&gt;
&lt;p&gt;If you find that such thinking manifests itself in dogmatic emails that state "static methods shouldn't be used because they inhibit testability" or "interfaces are bad because we can't get coverage with them." then it might be time to inspect both the situation and the tools and see that the two are being correctly paired.&lt;/p&gt;
&lt;p&gt;The goal of testing is to improve the quality of the end product, not to turn lots of lights a pretty shade of green.  8mph cars with lots of green LEDs and no doors for great dogmatic case study's and really awful consumer responses.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/105.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>Planning for the worst</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/25/104.aspx</link><pubDate>Fri, 25 Jul 2008 11:28:28 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/25/104.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/104.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/104.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/25/104.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/104.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Planning for the worst</source><description>&lt;p&gt;&lt;em&gt;"The status page we use to report service disruptions in progress is suffering a temporary misconfiguration."&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Brilliance!&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/104.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>Technorati Blog Claim</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/15/103.aspx</link><pubDate>Tue, 15 Jul 2008 12:19:20 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/15/103.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/103.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/103.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/15/103.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/103.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Technorati Blog Claim</source><description>I claim this blog in the name of Stuart Thompson for my new &lt;a href="http://technorati.com/claim/s9wmqqvsia"&gt;Technorati Profile&lt;/a&gt;.&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/103.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>LINQ to Coffee</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/15/102.aspx</link><pubDate>Tue, 15 Jul 2008 10:55:41 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/15/102.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/102.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/102.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/15/102.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/102.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">LINQ to Coffee</source><description>&lt;p&gt;Nice!  A perfect addition to the reference material you keep within reach.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.cafepress.com/linq.225122905"&gt;http://www.cafepress.com/linq.225122905&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/102.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>Debugging Into .NET Source Code</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/14/101.aspx</link><pubDate>Mon, 14 Jul 2008 11:04:31 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/14/101.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/101.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/101.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/14/101.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/101.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">Debugging Into .NET Source Code</source><description>&lt;p&gt;Many have “heard” that you can now step into .NET source code when debugging in Visual Studio 2008.  For those who have not been doing this since the start of the year, you can find excellent instructions for configuring Visual Studio to get the necessary symbols &lt;a href="http://blogs.msdn.com/sburke/archive/2008/01/16/configuring-visual-studio-to-debug-net-framework-source-code.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;I highly recommend understanding this process and making it a part of your debugging routine.  It often becomes necessary to understand why the .NET framework is behaving in a certain fashion while developing.  By stepping into the source code and using the watch window, I’ve saved myself a lot of hours of head-scratching.  More often than not it’s as simple as understanding why an exception was thrown and the hidden meaning behind the message.  Within minutes I can usually pinpoint how I was incorrectly using one of the libraries, fix the bug, and be on my way.&lt;/p&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/101.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item><item><title>LINQ'd In #1 - Behavior Injection</title><link>http://blogs.sftsrc.com/stuart/archive/2008/07/14/100.aspx</link><pubDate>Mon, 14 Jul 2008 09:51:44 GMT</pubDate><guid isPermaLink="true">http://blogs.sftsrc.com/stuart/archive/2008/07/14/100.aspx</guid><wfw:comment>http://blogs.sftsrc.com/stuart/comments/100.aspx</wfw:comment><wfw:commentRss>http://blogs.sftsrc.com/stuart/comments/commentRss/100.aspx</wfw:commentRss><comments>http://blogs.sftsrc.com/stuart/archive/2008/07/14/100.aspx#comment</comments><slash:comments>0</slash:comments><trackback:ping>http://blogs.sftsrc.com/stuart/services/trackbacks/100.aspx</trackback:ping><source url="http://blogs.sftsrc.com/stuart/rss.aspx">LINQ'd In #1 - Behavior Injection</source><description>&lt;p&gt;As part of a continuing set of articles on LINQ, I want to first take a moment to look at how the "natural" syntax of LINQ is turned into executable code.  Once we understand how those expressions and compiled we can investigate ways to extend the code that is being executed.&lt;/p&gt;
&lt;p&gt;First of all let’s consider a very simple LINQ expression:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New" color="#0000ff"&gt;from&lt;/font&gt;&lt;font face="Courier New"&gt; num &lt;/font&gt;&lt;font face="Courier New" color="#0000ff"&gt;in&lt;/font&gt;&lt;font face="Courier New"&gt; Enumerable.Range(&lt;/font&gt;&lt;font face="Courier New" color="#c81efa"&gt;1&lt;/font&gt;&lt;font face="Courier New"&gt;,&lt;/font&gt;&lt;font face="Courier New" color="#c81efa"&gt;9&lt;/font&gt;&lt;font face="Courier New"&gt;)&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff"&gt;where&lt;/font&gt;&lt;font face="Courier New"&gt; num % &lt;/font&gt;&lt;font face="Courier New" color="#c81efa"&gt;2&lt;/font&gt;&lt;font face="Courier New"&gt; == &lt;/font&gt;&lt;font face="Courier New" color="#c81efa"&gt;0&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New" color="#0000ff"&gt;select&lt;/font&gt;&lt;font face="Courier New"&gt; num&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;This expression selects the even numbers in the series 1–9.  Let’s first break this down into the actual code that is being executed.  Behind the scenes LINQ is viewing this expression as a series of lambda expressions and extension methods.  Our example is actually being run as:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;Enumerable.Range(&lt;font color="#993300"&gt;1&lt;/font&gt;,&lt;font color="#993300"&gt;9&lt;/font&gt;).Where(n =&amp;gt; n % &lt;font color="#993300"&gt;2&lt;/font&gt; == &lt;font color="#993300"&gt;0&lt;/font&gt;)&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;Enumerable.Range(1,9) &lt;/font&gt;yields an &lt;font face="Courier New"&gt;IEnumerable&amp;lt;int&amp;gt;&lt;/font&gt;.  By using &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt; we can discover that the signature of the Where method looks like the following:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public static&lt;/font&gt; IEnumerable&amp;lt;TSource&amp;gt; Where&amp;lt;TSource&amp;gt;(&lt;br /&gt;&lt;font color="#0000ff"&gt;    this&lt;/font&gt; IEnumerable&amp;lt;TSource&amp;gt; source, &lt;br /&gt;    Func&amp;lt;TSource, bool&amp;gt; predicate)&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;This is clearly an extension method on &lt;font face="Courier New"&gt;IEnumerable&amp;lt;TSource&amp;gt;&lt;/font&gt; that takes a &lt;font face="Courier New"&gt;Func&amp;lt;TSource, bool&amp;gt;&lt;/font&gt; as its only parameter.  While the actual internals of the Where method are actually a little more complex due to the way in which iterators have been abstracted, we could theorize that the behavior is roughly similar to the following:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public static&lt;/font&gt; IEnumerable&amp;lt;TSource&amp;gt; Where&amp;lt;TSource&amp;gt;(&lt;br /&gt;    &lt;font color="#0000ff"&gt;this&lt;/font&gt; IEnumerable&amp;lt;TSource&amp;gt; source, &lt;br /&gt;    Func&amp;lt;TSource, &lt;font color="#0000ff"&gt;bool&lt;/font&gt;&amp;gt; predicate)&lt;br /&gt;{&lt;br /&gt;    &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (TSource t &lt;font color="#0000ff"&gt;in&lt;/font&gt; source)&lt;br /&gt;    {&lt;br /&gt;       &lt;font color="#0000ff"&gt; if&lt;/font&gt; (predicate.Invoke(t) == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)&lt;br /&gt;            &lt;font color="#0000ff"&gt;yield return&lt;/font&gt; t;&lt;br /&gt;    }&lt;br /&gt;}&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;“For each item in the supplied &lt;font face="Courier New"&gt;IEnumerable&lt;/font&gt;, invoke the supplied &lt;em&gt;predicate&lt;/em&gt; and add the item to the returned collection if that predicate returned true.”&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: If you haven’t encountered keyword yield before, check out &lt;/em&gt;&lt;a href="http://www.stuartthompson.net/SubTextBlog/softwareengineering/archive/2008/06/16/93.aspx"&gt;&lt;em&gt;this post about how it works&lt;/em&gt;&lt;/a&gt;&lt;em&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Now that we understand how the statement is working internally, lets look at ways in which we can extend it.  To understand the following trick we need to think for a second about how extension methods are implemented, or more importantly about how they are resolved.&lt;/p&gt;
&lt;p&gt;When the compiler encounters a statement of the form:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ddffdd"&gt;&lt;font face="Courier New"&gt;&amp;lt;type&amp;gt;.&amp;lt;method&amp;gt;()&lt;/font&gt;         (e.g. &lt;font face="Courier New"&gt;IEnumerable&amp;lt;int&amp;gt;.Where(…)&lt;/font&gt;)&lt;/div&gt;
&lt;p&gt;for which there is no explicitly defined method, it searches the current list of scoped namespaces for an extension method that matches the implied signature.  The System.Linq namespace defines the extension method we’ve been examining above.  However, what if we wanted to use our own method instead of the System.Linq version of &lt;font face="Courier New"&gt;Where()?&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;We might want to add in some logging statements when the predicate finds a match.  Let’s do this right now by adding our own extension method for the &lt;font face="Courier New"&gt;IList&amp;lt;T&amp;gt;&lt;/font&gt; generic.  To do this we need to define a static class that contains a static &lt;font face="Courier New"&gt;Where&lt;/font&gt; method that has this &lt;font face="Courier New"&gt;IList&amp;lt;T&amp;gt;&lt;/font&gt; as its first parameter:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public static class&lt;/font&gt; ListExtensions&lt;br /&gt;{&lt;br /&gt;    &lt;font color="#0000ff"&gt;public static&lt;/font&gt; IEnumerable&amp;lt;T&amp;gt; Where&amp;lt;T&amp;gt;(&lt;br /&gt;        this IList&amp;lt;T&amp;gt; source, Func&amp;lt;T, &lt;font color="#0000ff"&gt;bool&lt;/font&gt;&amp;gt; predicate)&lt;br /&gt;    {&lt;br /&gt;        &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (T t &lt;font color="#0000ff"&gt;in&lt;/font&gt; source)&lt;br /&gt;        {&lt;br /&gt;            &lt;font color="#0000ff"&gt;if&lt;/font&gt; (predicate.Invoke(t) == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(&lt;br /&gt;                    String.Format&lt;font color="#993300"&gt;("Predicate indicated success for value: {0}"&lt;/font&gt;, t));&lt;br /&gt;                &lt;font color="#0000ff"&gt;yield return&lt;/font&gt; t;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;This method is almost identical to the theoretical version of Where we built above.  The only differences are that it extends &lt;font face="Courier New"&gt;IList&amp;lt;T&amp;gt;&lt;/font&gt; instead of &lt;font face="Courier New"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/font&gt; and that it logs when the predicate finds a match prior to yielding the matched item.&lt;/p&gt;
&lt;p&gt;Now let’s put together a little snippet that will exercise this extension method.  We can actually use the first sample we used in this post and by simply adding &lt;font face="Courier New"&gt;ToList()&lt;/font&gt; to the end of &lt;font face="Courier New"&gt;Enumerable.Range(1,9)&lt;/font&gt; we’ll be calling our extension method for &lt;font face="Courier New"&gt;Where()&lt;/font&gt; instead of the built-in System.Linq version.  Let’s look at that sample:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;from&lt;/font&gt; num &lt;font color="#0000ff"&gt;in&lt;/font&gt; Enumerable.Range(&lt;font color="#c81efa"&gt;1&lt;/font&gt;,&lt;font color="#c81efa"&gt;9&lt;/font&gt;).ToList()&lt;br /&gt;&lt;font color="#0000ff"&gt;where&lt;/font&gt; num % &lt;font color="#c81efa"&gt;2&lt;/font&gt; == &lt;font color="#c81efa"&gt;0&lt;/font&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;select&lt;/font&gt; num&lt;/font&gt;&lt;/div&gt;
&lt;p&gt;By simply adding the &lt;font face="Courier New"&gt;ToList()&lt;/font&gt; to the sample above we’ve caused the compiler to call our new &lt;font face="Courier New"&gt;Where()&lt;/font&gt; method.  This gives a pretty clear idea of how LINQ is working internally and what’s actually going on when we use the new C# 3.0 language keywords.  There is a lot less voodoo involved in the process that one might first believe!&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Example Listing&lt;/strong&gt;&lt;br /&gt;The following is a complete example suitable for pasting into &lt;a href="http://www.sliver.com/dotnet/SnippetCompiler/"&gt;snippet compiler&lt;/a&gt;:&lt;/p&gt;
&lt;div style="BORDER-RIGHT: #444444 1px solid; PADDING-RIGHT: 3px; BORDER-TOP: #444444 1px solid; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; BORDER-LEFT: #444444 1px solid; PADDING-TOP: 3px; BORDER-BOTTOM: #444444 1px solid; BACKGROUND-COLOR: #ffffdd"&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System;&lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Collections.Generic;&lt;br /&gt;&lt;font color="#0000ff"&gt;using&lt;/font&gt; System.Linq;&lt;/font&gt; 
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public class&lt;/font&gt; MyClass&lt;br /&gt;{&lt;br /&gt;    &lt;font color="#0000ff"&gt;public static void&lt;/font&gt; RunSnippet()&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(&lt;font color="#993300"&gt;"Results using the IEnumerable&amp;lt;T&amp;gt;.Where() method from System.Linq."&lt;/font&gt;);&lt;br /&gt;        &lt;font color="#0000ff"&gt;var&lt;/font&gt; enumResults = &lt;br /&gt;            &lt;font color="#0000ff"&gt;from&lt;/font&gt; n &lt;font color="#0000ff"&gt;in&lt;/font&gt; Enumerable.Range(&lt;font color="#993300"&gt;1&lt;/font&gt;,&lt;font color="#993300"&gt;9&lt;/font&gt;)&lt;br /&gt;            &lt;font color="#0000ff"&gt;where&lt;/font&gt; n % 2 == 0&lt;br /&gt;            &lt;font color="#0000ff"&gt;select&lt;/font&gt; n;&lt;br /&gt;        &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt; n &lt;font color="#0000ff"&gt;in&lt;/font&gt; enumResults)&lt;br /&gt;            Console.WriteLine(n);&lt;br /&gt;        &lt;br /&gt;        Console.WriteLine(&lt;font color="#993300"&gt;"Results using the custom IList&amp;lt;T&amp;gt;.Where() method from this sample."&lt;/font&gt;);&lt;br /&gt;        &lt;font color="#0000ff"&gt;var&lt;/font&gt; listResults = &lt;br /&gt;            &lt;font color="#0000ff"&gt;from&lt;/font&gt; n &lt;font color="#0000ff"&gt;in&lt;/font&gt; Enumerable.Range(&lt;font color="#993300"&gt;1&lt;/font&gt;,&lt;font color="#993300"&gt;9&lt;/font&gt;).ToList()&lt;br /&gt;            &lt;font color="#0000ff"&gt;where&lt;/font&gt; n % 2 == 0&lt;br /&gt;            &lt;font color="#0000ff"&gt;select&lt;/font&gt; n;&lt;br /&gt;        &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (&lt;font color="#0000ff"&gt;int&lt;/font&gt; n &lt;font color="#0000ff"&gt;in&lt;/font&gt; listResults)&lt;br /&gt;            Console.WriteLine(n);&lt;br /&gt;    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;    &lt;br /&gt;    &lt;br /&gt;    &lt;font color="#0000ff"&gt;#region&lt;/font&gt; Helper methods&lt;br /&gt;    &lt;br /&gt;    &lt;font color="#0000ff"&gt;public static void&lt;/font&gt; Main()&lt;br /&gt;    {&lt;br /&gt;        &lt;font color="#0000ff"&gt;try&lt;/font&gt;&lt;br /&gt;        {&lt;br /&gt;            RunSnippet();&lt;br /&gt;        }&lt;br /&gt;        &lt;font color="#0000ff"&gt;catch&lt;/font&gt; (Exception e)&lt;br /&gt;        {&lt;br /&gt;            &lt;font color="#0000ff"&gt;string&lt;/font&gt; error = &lt;font color="#0000ff"&gt;string&lt;/font&gt;.Format(&lt;font color="#993300"&gt;"---\nThe following error occurred while executing the snippet:\n{0}\n---"&lt;/font&gt;, e.ToString());&lt;br /&gt;            Console.WriteLine(error);&lt;br /&gt;        }&lt;br /&gt;        &lt;font color="#0000ff"&gt;finally&lt;/font&gt;&lt;br /&gt;        {&lt;br /&gt;            Console.Write(&lt;font color="#993300"&gt;"Press any key to continue..."&lt;/font&gt;);&lt;br /&gt;            Console.ReadKey();&lt;br /&gt;        }&lt;br /&gt;    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;    &lt;font color="#0000ff"&gt;private static void&lt;/font&gt; WL(&lt;font color="#0000ff"&gt;object&lt;/font&gt; text, &lt;font color="#0000ff"&gt;params&lt;/font&gt; &lt;font color="#0000ff"&gt;object&lt;/font&gt;[] args)&lt;br /&gt;    {&lt;br /&gt;        Console.WriteLine(text.ToString(), args);    &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;font color="#0000ff"&gt;private static void&lt;/font&gt; RL()&lt;br /&gt;    {&lt;br /&gt;        Console.ReadLine();    &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    &lt;font color="#0000ff"&gt;private static void&lt;/font&gt; Break() &lt;br /&gt;    {&lt;br /&gt;        System.Diagnostics.Debugger.Break();&lt;br /&gt;    }&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;    &lt;font color="#0000ff"&gt;#endregion&lt;br /&gt;&lt;/font&gt;}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&lt;font color="#0000ff"&gt;public static class&lt;/font&gt; ListExtensions&lt;br /&gt;{&lt;br /&gt;    &lt;font color="#0000ff"&gt;public static&lt;/font&gt; IEnumerable&amp;lt;T&amp;gt; Where&amp;lt;T&amp;gt;(&lt;font color="#0000ff"&gt;this&lt;/font&gt; IList&amp;lt;T&amp;gt; source, Func&amp;lt;T, &lt;font color="#0000ff"&gt;bool&lt;/font&gt;&amp;gt; predicate)&lt;br /&gt;    {&lt;br /&gt;        &lt;font color="#0000ff"&gt;foreach&lt;/font&gt; (T t &lt;font color="#0000ff"&gt;in&lt;/font&gt; source)&lt;br /&gt;        {&lt;br /&gt;            &lt;font color="#0000ff"&gt;if&lt;/font&gt; (predicate.Invoke(t) == &lt;font color="#0000ff"&gt;true&lt;/font&gt;)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(String.Format(&lt;font color="#993300"&gt;"Predicate indicated success for value: {0}"&lt;/font&gt;, t));&lt;br /&gt;                &lt;font color="#0000ff"&gt;yield return&lt;/font&gt; t;&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;/div&gt;&lt;img src="http://blogs.sftsrc.com/stuart/aggbug/100.aspx" width="1" height="1" /&gt;</description><dc:creator>Stuart Thompson</dc:creator></item></channel></rss>