<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en-us">
  <title>Generic Error</title>
  <link rel="alternate" type="text/html" href="http://www.genericerror.com/blog/" />
  
  <icon>favicon.ico</icon>
  <updated>2009-10-20T07:18:24.0732857-07:00</updated>
  <author>
    <name>Barry Dahlberg</name>
  </author>
  <subtitle>Personal web log of Barry Dahlberg.</subtitle>
  <id>http://www.genericerror.com/blog/</id>
  <generator uri="http://dasblog.info/" version="2.2.8279.16125">DasBlog</generator>
  <link rel="self" href="http://feeds.feedburner.com/GenericError" type="application/atom+xml" /><feedburner:emailServiceId>GenericError</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry>
    <title>OpenRasta Documentation</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/ZJKo0PnBPuc/OpenRastaDocumentation.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,5bd9212d-fafa-4f15-b0fc-44d4e86523e4.aspx</id>
    <published>2009-10-20T07:18:24.0732857-07:00</published>
    <updated>2009-10-20T07:18:24.0732857-07:00</updated>
    <category term="Open Rasta" label="Open Rasta" scheme="http://www.genericerror.com/blog/CategoryView,category,OpenRasta.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/T7dxag622V6q5DwzKsRzEPTn7uA/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T7dxag622V6q5DwzKsRzEPTn7uA/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/T7dxag622V6q5DwzKsRzEPTn7uA/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/T7dxag622V6q5DwzKsRzEPTn7uA/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I notice that Google is having a little trouble finding the OpenRasta documentation&#xD;
so I figure it needs a little link love.  Here we go…&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://trac.caffeine-it.com/openrasta/wiki/Doc" target="_blank"&gt;OpenRasta&#xD;
Community Documentation&lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=5bd9212d-fafa-4f15-b0fc-44d4e86523e4"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/ZJKo0PnBPuc" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/10/20/OpenRastaDocumentation.aspx</feedburner:origLink></entry>
  <entry>
    <title>Logging Open Rasta Errors With ELMAH</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/KMK_FlLOicc/LoggingOpenRastaErrorsWithELMAH.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,8beab411-e70d-44ec-a8f1-ff3fdb7e6096.aspx</id>
    <published>2009-09-06T10:48:00-07:00</published>
    <updated>2009-09-03T03:48:55.8178457-07:00</updated>
    <category term="ASP.Net" label="ASP.Net" scheme="http://www.genericerror.com/blog/CategoryView,category,ASPNet.aspx" />
    <category term="ELMAH" label="ELMAH" scheme="http://www.genericerror.com/blog/CategoryView,category,ELMAH.aspx" />
    <category term="Open Rasta" label="Open Rasta" scheme="http://www.genericerror.com/blog/CategoryView,category,OpenRasta.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/FTBBILAy8JMDrK_3WYuR0Y_juao/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FTBBILAy8JMDrK_3WYuR0Y_juao/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/FTBBILAy8JMDrK_3WYuR0Y_juao/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/FTBBILAy8JMDrK_3WYuR0Y_juao/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
In my &lt;a href="http://www.genericerror.com/blog/2009/09/03/ThingsThatMakeMeSmile.aspx"&gt;previous&#xD;
post&lt;/a&gt; I mentioned that I have been using both &lt;a href="http://trac.caffeine-it.com/openrasta/wiki/Doc"&gt;Open&#xD;
Rasta&lt;/a&gt; and &lt;a href="http://code.google.com/p/elmah/"&gt;ELMAH&lt;/a&gt; so this post explains&#xD;
how to make them play nicely together.  To get started you will need to set up&#xD;
both libraries in your project as per their documentation, then follow along below.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Open Rasta actually attempts to handle its errors rather than letting them fall out&#xD;
to ASP.Net’s normal unhandled exception events.  This means that ELMAH never&#xD;
hears about them and doesn’t log them by default.  Fortunately both Open Rasta&#xD;
and ELMAH provide easy hooks for us to easily set this up.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Manually Logging With ELMAH&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Sometimes you have exceptions which don’t represent a complete application meltdown&#xD;
but you would like to know about anyway.  ELMAH has an API set up for just such&#xD;
an occasion:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: #2b91af"&gt;ErrorSignal&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        .FromCurrentContext()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        .Raise(ex);&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This simple call grabs the current ELMAH setup from HttpContext and passes it any&#xD;
exception we want.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Injecting A Logger Into Open Rasta&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Open Rasta logs exceptions and lots of other useful information while it is running. &#xD;
By default this information is logged to .Net trace output but we’re going to replace&#xD;
that.  Here’s a simple logger that will do the job:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ElmahLogger&lt;/span&gt; :&#xD;
OpenRasta.Diagnostics.&lt;span style="color: #2b91af"&gt;ILogger&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; WriteException(&lt;span style="color: #2b91af"&gt;Exception&lt;/span&gt; ex)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
       {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;ErrorSignal&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
.FromCurrentContext()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
              &#xD;
.Raise(ex);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; WriteDebug(&lt;span style="color: blue"&gt;string&lt;/span&gt; message, &lt;span style="color: blue"&gt;params&lt;/span&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
f) { }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; WriteWarning(&lt;span style="color: blue"&gt;string&lt;/span&gt; message, &lt;span style="color: blue"&gt;params&lt;/span&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
f) { }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; WriteError(&lt;span style="color: blue"&gt;string&lt;/span&gt; message, &lt;span style="color: blue"&gt;params&lt;/span&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
f) { }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; WriteInfo(&lt;span style="color: blue"&gt;string&lt;/span&gt; message, &lt;span style="color: blue"&gt;params&lt;/span&gt;&lt;span style="color: blue"&gt;object&lt;/span&gt;[]&#xD;
f) { }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;OperationContext&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;IDisposable&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Dispose()&#xD;
{ }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;IDisposable&lt;/span&gt; Operation(&lt;span style="color: blue"&gt;object&lt;/span&gt; source, &lt;span style="color: blue"&gt;string&lt;/span&gt; name)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt;&lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;OperationContext&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The important lines are in the &lt;em&gt;WriteException&lt;/em&gt; method at the top.  You&#xD;
can use the rest of the methods to gather a full log from Open Rasta’s pipeline to&#xD;
include in the exception details if you want.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Since Open Rasta has a simple dependency injection container built right in, telling&#xD;
it to use our logger simply requires adding these lines to your normal configuration:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-family: courier new; background: white; color: black; font-size: 10pt"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: #2b91af"&gt;ResourceSpace&lt;/span&gt;.Uses&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        .CustomDependency&amp;lt;&lt;span style="color: #2b91af"&gt;ILogger&lt;/span&gt;, &lt;span style="color: #2b91af"&gt;ElmahLogger&lt;/span&gt;&amp;gt;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        (&lt;span style="color: #2b91af"&gt;DependencyLifetime&lt;/span&gt;.Singleton);&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
That wasn’t so bad now was it?&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=8beab411-e70d-44ec-a8f1-ff3fdb7e6096"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/KMK_FlLOicc" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/09/06/LoggingOpenRastaErrorsWithELMAH.aspx</feedburner:origLink></entry>
  <entry>
    <title>Things That Make Me Smile</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/zx8zy-MnBTg/ThingsThatMakeMeSmile.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,5d693aaf-913b-4bea-bf1f-cdb9ea01188e.aspx</id>
    <published>2009-09-03T02:29:26.2139513-07:00</published>
    <updated>2009-09-03T02:29:26.2139513-07:00</updated>
    <category term="ASP.Net" label="ASP.Net" scheme="http://www.genericerror.com/blog/CategoryView,category,ASPNet.aspx" />
    <category term="Composite WPF" label="Composite WPF" scheme="http://www.genericerror.com/blog/CategoryView,category,CompositeWPF.aspx" />
    <category term="ELMAH" label="ELMAH" scheme="http://www.genericerror.com/blog/CategoryView,category,ELMAH.aspx" />
    <category term="Open Rasta" label="Open Rasta" scheme="http://www.genericerror.com/blog/CategoryView,category,OpenRasta.aspx" />
    <category term="Smile" label="Smile" scheme="http://www.genericerror.com/blog/CategoryView,category,Smile.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/c0j5qjuIrBesqbHe5qkexXjhYAo/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c0j5qjuIrBesqbHe5qkexXjhYAo/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/c0j5qjuIrBesqbHe5qkexXjhYAo/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/c0j5qjuIrBesqbHe5qkexXjhYAo/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
It’s been a while so I thought I’d start my return to blogging on a happy note. &#xD;
Here’s a few products I’ve used lately that have made me happy.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Open Rasta&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
I’ve tried a couple of times to implement a simple REST API using WCF lately and it&#xD;
always frustrates me.  It’s not really hard, it’s just harder than it needs to&#xD;
be.  That’s why I ended up looking for alternatives.&#xD;
&lt;/p&gt;&#xD;
        &lt;blockquote&gt;&#xD;
          &lt;p&gt;&#xD;
            &lt;em&gt;&#xD;
              &lt;a href="http://trac.caffeine-it.com/openrasta/wiki/Doc"&gt;OpenRasta&lt;/a&gt;&#xD;
            &lt;/em&gt;&#xD;
            &lt;em&gt; is&#xD;
a resource-oriented framework for .NET enabling easy ReST-ful development of web sites&#xD;
and services.&lt;/em&gt;&#xD;
          &lt;/p&gt;&#xD;
        &lt;/blockquote&gt;&#xD;
        &lt;p&gt;&#xD;
If you’re a fan of simple convention based frameworks then this is one to keep an&#xD;
eye on.  The framework is built around a customisable pipeline which allows you&#xD;
to easily drop in your own components using a simple fluent API and built in dependency&#xD;
injection.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
It’s currently in it’s second beta and is still a bit rough around the edges but I&#xD;
had no problems putting together a simple API and customising it to suit.  The&#xD;
documentation is still lacking but the driver behind the project, &lt;a href="http://serialseb.blogspot.com/"&gt;Sebastien&#xD;
Lambla&lt;/a&gt;, is active on the &lt;a href="http://groups.google.com/group/openrasta"&gt;mailing&#xD;
list&lt;/a&gt; and has been a big help getting me off the ground.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The best thing about &lt;a href="http://trac.caffeine-it.com/openrasta/wiki/Doc"&gt;Open&#xD;
Rasta&lt;/a&gt;?  It’s distributed under the very friendly MIT license.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;ELMAH&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
I look after a lot of different ASP.Net web sites sites so it can be weeks before&#xD;
I discover problems with them on my own.  &lt;a href="http://code.google.com/p/elmah/"&gt;ELMAH&#xD;
(Error Logging Modules and Handlers)&lt;/a&gt;, has been a great tool for quickly and consistently&#xD;
setting up basic error handling.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Personally I just use it to send all errors as emails to myself but there’s all sorts&#xD;
of features to keep you busy if you have larger requirements.  My favourite feature&#xD;
is the lovingly preserved Yellow Screen Of Death that arrives in my inbox full of&#xD;
details about the failed request.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Composite WPF (Prism)&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Why do I like the &lt;a href="http://www.codeplex.com/CompositeWPF"&gt;Composite WPF&lt;/a&gt; library&#xD;
so much?  Mostly because I am unfortunate enough that I have to work one of that&#xD;
teams previous products, the &lt;a href="http://smartclient.codeplex.com/"&gt;Composite&#xD;
Application Block&lt;/a&gt;.  This time around the team have managed to present their&#xD;
concepts in a clear and understandable manner that doesn’t make my head hurt.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
In particular the complex work items system of previous versions is gone and replaced&#xD;
with a simple application of their IoC container, &lt;a href="http://www.codeplex.com/Wiki/View.aspx?ProjectName=unity"&gt;Unity&lt;/a&gt;. &#xD;
Whether or not you actually need such a framework is up to you to decide but if you&#xD;
have been scared off by CAB in the past don’t be afraid to take another look.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Keep smiling until next time!&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=5d693aaf-913b-4bea-bf1f-cdb9ea01188e"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/zx8zy-MnBTg" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/09/03/ThingsThatMakeMeSmile.aspx</feedburner:origLink></entry>
  <entry>
    <title>Can Games Teach You To Program?</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/CKqfJ5ZunQE/CanGamesTeachYouToProgram.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,931e1c9f-c236-43b3-a6c2-25792b41eebf.aspx</id>
    <published>2009-02-27T00:54:53.4688324-08:00</published>
    <updated>2009-02-27T00:56:16.5872308-08:00</updated>
    <category term="Games" label="Games" scheme="http://www.genericerror.com/blog/CategoryView,category,Games.aspx" />
    <category term="Teaching" label="Teaching" scheme="http://www.genericerror.com/blog/CategoryView,category,Teaching.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/SbEdcu0ClLfnP23r538O3YqLOBg/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SbEdcu0ClLfnP23r538O3YqLOBg/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/SbEdcu0ClLfnP23r538O3YqLOBg/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/SbEdcu0ClLfnP23r538O3YqLOBg/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
After getting severely distracted by a little gem called &lt;a href="http://robozzle.com/"&gt;RoboZZle&lt;/a&gt; I'd&#xD;
had to answer with a solid &lt;em&gt;maybe&lt;/em&gt;.  The idea behind the game is simple:&#xD;
for each puzzle, program a small robot to collect all of the stars without falling&#xD;
off the map.  Here's a an example of a typical puzzle:&#xD;
&lt;/p&gt;&#xD;
        &lt;a href="http://igoro.com/wordpress/wp-content/uploads/2009/02/robozzle-designer.jpg"&gt;&#xD;
          &lt;img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="147" alt="robozzle_designer" src="http://igoro.com/wordpress/wp-content/uploads/2009/02/robozzle-designer-thumb.jpg" width="244" border="0"&gt;&lt;/img&gt;&#xD;
        &lt;/a&gt;&#xD;
        &lt;p&gt;&#xD;
What's really cool is that the author, &lt;a href="http://igoro.com"&gt;Igor Ostrovsky&lt;/a&gt;,&#xD;
has added social features so if you sign up for an account you can rate and vote for&#xD;
puzzles as well as submitting your own.  This frees Igor from having to dream&#xD;
up all the puzzles and adds a lot more variety and a lot more devious minds the mix!&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
No modern programming language looks anything like the one used in the game, at least,&#xD;
not one anyone uses...  so what could it possibly have to teach us?  Well,&#xD;
solving all of the puzzles will require you to do all of these:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Search for patterns.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Invent algorithms.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Create reusable functions.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Understand recursion.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Simplify.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
There's one item in that list that is essential for solving many of the harder problems,&#xD;
and it's one that still gives a lot programmers headaches in the real world...&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Understand Recursion&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
A function that calls itself, what's so hard about that?  If you think you really&#xD;
understand recursion here's some puzzles to try, starting with something nice and&#xD;
easy and working up to trickier problems:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://robozzle.com/index.aspx?puzzle=27"&gt;Stairways to Heaven&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://robozzle.com/index.aspx?puzzle=59"&gt;Recursion&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://robozzle.com/index.aspx?puzzle=33"&gt;Can you count?&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://robozzle.com/index.aspx?puzzle=34"&gt;Don't fall off the spiral&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
Made it this far?  Well done.  As a final exam I put together a puzzle of&#xD;
my own.  At the time of writing is remains unsolved, let me know how you get&#xD;
on...&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
            &lt;a href="http://robozzle.com/index.aspx?puzzle=66"&gt;Reflection&lt;/a&gt;&#xD;
          &lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
So yes, maybe there is something games can teach us.  If so I'm going to be a&#xD;
genius!  Oh yeah, the game is built in Silverlight too which is just awesome.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=931e1c9f-c236-43b3-a6c2-25792b41eebf"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/CKqfJ5ZunQE" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/02/27/CanGamesTeachYouToProgram.aspx</feedburner:origLink></entry>
  <entry>
    <title>ASP.Net MVC Custom Error Pages</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/xe_7VCI8QYA/ASPNetMVCCustomErrorPages.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,7b3233c1-3df1-4715-94a1-94f5f5f4f66f.aspx</id>
    <published>2009-01-27T04:34:38.076894-08:00</published>
    <updated>2009-01-27T04:34:38.076894-08:00</updated>
    <category term="ASP.Net" label="ASP.Net" scheme="http://www.genericerror.com/blog/CategoryView,category,ASPNet.aspx" />
    <category term="Custom Errors" label="Custom Errors" scheme="http://www.genericerror.com/blog/CategoryView,category,CustomErrors.aspx" />
    <category term="MVC" label="MVC" scheme="http://www.genericerror.com/blog/CategoryView,category,MVC.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/DCosl3fdZBEYp1h_sm_6KxSTM5c/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DCosl3fdZBEYp1h_sm_6KxSTM5c/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/DCosl3fdZBEYp1h_sm_6KxSTM5c/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/DCosl3fdZBEYp1h_sm_6KxSTM5c/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I have recently spent quite a bit of time getting my ASP.Net MVC application to display&#xD;
errors to the user the way I want and this post outlines the steps I took to get there. &#xD;
This includes general application errors, page not found errors and stupid user errors. &#xD;
A basic understanding of ASP.Net and the MVC framework will be required to follow&#xD;
this post.  For reference my environment looks like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Windows Server 2008&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
IIS7 using the Integrated Pipeline&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Visual Studio 2008&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
ASP.Net MVC Beta&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
If you have a different setup the details provided here might not work exactly as&#xD;
described, especially if you are running a lesser version of IIS like 5 or 6. &#xD;
Upgrade, seriously.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;CustomErrors Web.config Settings&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Remember, ASP.Net MVC is just a new layer on top of the same old ASP.Net we know and &lt;strike&gt;love&lt;/strike&gt;&lt;strike&gt;hate&lt;/strike&gt; put&#xD;
up with.  The custom errors section of the &lt;em&gt;Web.config&lt;/em&gt; was something&#xD;
we always had to set up for web forms projects so it seems like a good place to start&#xD;
for MVC.  Here's what my settings look like:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;    &amp;lt;&lt;/span&gt;&#xD;
            &lt;span style="color: #a31515"&gt;customErrors&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;&#xD;
            &lt;/span&gt;&#xD;
            &lt;span style="color: red"&gt;mode&lt;/span&gt;&#xD;
            &lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;On&lt;/span&gt;"&lt;span style="color: blue"&gt;&lt;/span&gt;&lt;span style="color: red"&gt;defaultRedirect&lt;/span&gt;&lt;span style="color: blue"&gt;=&lt;/span&gt;"&lt;span style="color: blue"&gt;~/Error/Unknown&lt;/span&gt;"&lt;span style="color: blue"&gt; /&amp;gt;&lt;/span&gt;&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Nice and simple.  All I'm saying here is that should anything crazy happen that&#xD;
my application doesn't deal with, redirect the user to my &lt;em&gt;really bad error&lt;/em&gt; page. &#xD;
The URL I provide is going to map to one on my MVC controllers which I'll get to shortly.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
ASP.Net allows you to add rules for specific HTTP status codes but I'm going to ignore&#xD;
all that because I want these settings to be used as little as possible.  If&#xD;
you're interested in why there are already plenty of people out there talking about&#xD;
the issues with custom errors, e.g. &lt;a href="http://www.colincochrane.com/post/2008/01/25/ASP-NET-Custom-Errors-Preventing-302-Redirects-To-Custom-Error-Pages.aspx"&gt;this&#xD;
guy&lt;/a&gt;, &lt;a href="http://www.evanclosson.com/devlog/bettercustomerrorsinaspnet"&gt;that&#xD;
guy&lt;/a&gt; and &lt;a href="http://www.ryoushin.com/cmerighi/en-us/36,2007-01-06/404_vs_302_ASP_Net_Custom_Errors.aspx"&gt;another&#xD;
guy also&lt;/a&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;ErrorController&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
In my application I have a controller dedicated to serving up application level errors. &#xD;
Here's a simplified version:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ErrorController&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Controller&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        [&lt;span style="color: #2b91af"&gt;AcceptVerbs&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpVerbs&lt;/span&gt;.Get)]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ViewResult&lt;/span&gt; Unknown()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            Response.StatusCode&#xD;
= (&lt;span style="color: blue"&gt;int&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;HttpStatusCode&lt;/span&gt;.InternalServerError;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515"&gt;"Unknown"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        [&lt;span style="color: #2b91af"&gt;AcceptVerbs&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpVerbs&lt;/span&gt;.Get)]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ViewResult&lt;/span&gt; NotFound(&lt;span style="color: blue"&gt;string&lt;/span&gt; path)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            Response.StatusCode&#xD;
= (&lt;span style="color: blue"&gt;int&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;HttpStatusCode&lt;/span&gt;.NotFound;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515"&gt;"NotFound"&lt;/span&gt;,&#xD;
path);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The &lt;em&gt;Unknown&lt;/em&gt; action is the target of my custom errors redirect in the Web.config. &#xD;
The &lt;em&gt;NotFound&lt;/em&gt; action is going to be used by the routing system which I will&#xD;
describe below.  Note that both actions set the HTTP status code to make sure&#xD;
our response is absolutely clear to the client.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There are intentionally few types of errors here because if the user is seeing these&#xD;
it probably means there is an improvement I can make to the application.  The&#xD;
views that these actions render are very generic and don't have enough context to&#xD;
be very useful to the user.  They may as well just say &lt;em&gt;Oops!&lt;/em&gt;&lt;/p&gt;&#xD;
        &lt;h4&gt;IIS7 Detailed Errors&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
IIS7, trying to be helpful, likes to steal your custom errors pages and replace them&#xD;
with it's own:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IIS7%20Error_2.png"&gt;&#xD;
            &lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="168" alt="IIS7 500 Internal Server Error" src="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IIS7%20Error_thumb.png" width="390" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Annoyingly these errors will be swapped in whenever you set the HTTP status code to&#xD;
something interesting.  To crack down on this insubordination you need to open&#xD;
the &lt;em&gt;Error Pages&lt;/em&gt; feature in IIS and click &lt;em&gt;Edit Feature Settings&lt;/em&gt; on&#xD;
the right hand menu to get this dialog:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IIS7%20Dialog_2.png"&gt;&#xD;
            &lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="369" alt="IIS7 Edit Error Pages Settings" src="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IIS7%20Dialog_thumb.png" width="400" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You might be tempted to think that the &lt;em&gt;Custom error pages&lt;/em&gt; option is what&#xD;
you should choose to display your custom error pages... but you'd be wrong. &#xD;
These are IIS7 custom errors pages and something else entirely from what we are after. &#xD;
Set the &lt;em&gt;Detailed errors&lt;/em&gt; option to have IIS pass through whatever errors we&#xD;
serve up from ASP.Net.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Internet Explorer Friendly Errors&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Internet Explorer, trying to be helpful like it's big brother IIS, wont display your&#xD;
error pages if they are smaller than 512 bytes.  By default IE has a setting&#xD;
called &lt;em&gt;Show friendly HTTP error messages&lt;/em&gt; turned on and this causes your nice&#xD;
custom errors to be replaced with the standard canned reply:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IE%20Error_2.png"&gt;&#xD;
            &lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="345" alt="IE Error" src="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/ASP.NetMVCConsistentCustomErrorPages_1462E/IE%20Error_thumb.png" width="408" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
You can find the option to turn this off in IE under &lt;em&gt;Tools, Internet Options,&#xD;
Advanced, Browsing, Show friendly HTTP error messages&lt;/em&gt;.  Unfortunately you&#xD;
can't set this for all of your users (or install Firefox for them) so just make sure&#xD;
that all of your error pages are larger than 512 bytes and you should be fine.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I find this one to be quite annoying during development when I only have stub pages&#xD;
in place.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Page Not Found&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
One of the most basic errors all sites will need to serve is the standard 404, page&#xD;
not found.  I could let the custom errors settings deal with this but as well&#xD;
as adding an extra redirect it also requires all requests to be mapped to ASP.Net&#xD;
in IIS, even those without a standard extension like &lt;em&gt;.aspx&lt;/em&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Keeping things in code is my preference as it makes them easier to test and easier&#xD;
to move to new environments.  The MVC routing features let me deal with this&#xD;
nicely by adding a simple catch all route after all my standard application routes:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    routes.MapRoute(&lt;span style="color: #a31515"&gt;"Default"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"{controller}/{action}/{id}"&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;new&lt;/span&gt; {&#xD;
controller = &lt;span style="color: #a31515"&gt;"Home"&lt;/span&gt;, action = &lt;span style="color: #a31515"&gt;"Index"&lt;/span&gt;,&#xD;
id = &lt;span style="color: #a31515"&gt;""&lt;/span&gt; });&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    routes.MapRoute(&lt;span style="color: #a31515"&gt;"Catch All"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"{*path}"&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;new&lt;/span&gt; {&#xD;
controller = &lt;span style="color: #a31515"&gt;"Error"&lt;/span&gt;, action = &lt;span style="color: #a31515"&gt;"NotFound"&lt;/span&gt; });&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This maps any completely invalid routes to &lt;em&gt;ErrorController.NotFound&lt;/em&gt; which&#xD;
we've already seen.  This happens in a single request, without any redirects,&#xD;
works with all URLs and doesn't require a special mapping in IIS.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Route Matched But Parameters Are Invalid&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
If you have controller actions that take parameters you need to take some additional&#xD;
steps with your routing.  An error that kept popping up for me early on was something&#xD;
like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;blockquote&gt;&#xD;
          &lt;p&gt;&#xD;
            &lt;em&gt;The parameters dictionary does not contain a valid value of type 'System.Int32'&#xD;
for parameter 'id' which is required for method 'System.Web.Mvc.ActionResult Edit(Int32)'&#xD;
in 'Example.ProductController'. To make a parameter optional its type should either&#xD;
be a reference type or a Nullable type.&lt;/em&gt;&#xD;
          &lt;/p&gt;&#xD;
        &lt;/blockquote&gt;&#xD;
        &lt;p&gt;&#xD;
Ouch, what?!  To get rid of these errors you can add constraints to your routes&#xD;
using regular expressions, e.g.&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    routes.MapRoute(&lt;span style="color: #a31515"&gt;"Products - Edit"&lt;/span&gt;, &lt;span style="color: #a31515"&gt;"Products/{id}/Edit"&lt;/span&gt;,&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;new&lt;/span&gt; {&#xD;
controller = &lt;span style="color: #a31515"&gt;"Products"&lt;/span&gt;, action = &lt;span style="color: #a31515"&gt;"Edit"&lt;/span&gt; },&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;new&lt;/span&gt; {&#xD;
id = &lt;span style="color: #a31515"&gt;@"\d{1,}"&lt;/span&gt; });&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The last line specifies that the &lt;em&gt;id&lt;/em&gt; parameter must be one or more digits&#xD;
an not contain any crazy stuff like letters or tilde symbols.  Should someone&#xD;
decide to be sneaky and type rubbish which the ID should go, they will pass right&#xD;
over this route and the catch all route will send them to the 404 page.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Errors In Controllers&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Even once a request has successfully been mapped to an action there is plenty that&#xD;
could go wrong.  Here's a simple example where the requested product isn't found&#xD;
in the database:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;    public&lt;/span&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;ProductController&#xD;
: Controller&lt;/span&gt;&#xD;
          &lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;    &lt;/span&gt;{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;    &lt;/span&gt;[&lt;span style="color: #2b91af"&gt;AcceptVerbs&lt;/span&gt;(&lt;span style="color: #2b91af"&gt;HttpVerbs&lt;/span&gt;.Get)]&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: #2b91af"&gt;ActionResult&lt;/span&gt; ViewDetails(&lt;span style="color: blue"&gt;int&lt;/span&gt; id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;    &lt;/span&gt;{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;    &lt;/span&gt;        &lt;span style="color: blue"&gt;var&lt;/span&gt; product&#xD;
= GetProductFromDB(id);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &lt;span style="color: blue"&gt;    &lt;/span&gt;       &lt;span style="color: blue"&gt;if&lt;/span&gt; (product&#xD;
== &lt;span style="color: blue"&gt;null&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
     &lt;span style="color: blue"&gt;    &lt;/span&gt;  &#xD;
{&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
         &lt;span style="color: blue"&gt;    &lt;/span&gt;  &#xD;
Response.StatusCode = (&lt;span style="color: blue"&gt;int&lt;/span&gt;)&lt;span style="color: #2b91af"&gt;HttpStatusCode&lt;/span&gt;.NotFound;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515"&gt;"NotFound"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;    &lt;/span&gt;}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;    &lt;/span&gt;&lt;span style="color: blue"&gt;return&lt;/span&gt; View(&lt;span style="color: #a31515"&gt;"Details"&lt;/span&gt;,&#xD;
product);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;    &lt;/span&gt;}&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
One of the advantages MVC has over the web forms model is that you can delay choosing&#xD;
which view to render right until the last moment.  Here I am using a not found&#xD;
page tailored specifically for the products section of the site so that I can try&#xD;
and guess what the user was looking for and give them as much help as possible.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
There are more advanced ways of catching errors in controller but they all basically&#xD;
have the same effect, rendering a different view.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Conclusion&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
That's all for today.  If you have any questions, comments or corrections I'd&#xD;
love to hear from you so leave a comment below.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=7b3233c1-3df1-4715-94a1-94f5f5f4f66f"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/xe_7VCI8QYA" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/01/27/ASPNetMVCCustomErrorPages.aspx</feedburner:origLink></entry>
  <entry>
    <title>Virtual Methods vs Extension Methods</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/rvV4X_sKGFA/VirtualMethodsVsExtensionMethods.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,a80023c4-579f-42cd-b5f7-7e7656872a2a.aspx</id>
    <published>2009-01-22T16:50:00.6221325-08:00</published>
    <updated>2009-01-22T16:50:00.6221325-08:00</updated>
    <category term="Extension Methods" label="Extension Methods" scheme="http://www.genericerror.com/blog/CategoryView,category,ExtensionMethods.aspx" />
    <category term="LINQ" label="LINQ" scheme="http://www.genericerror.com/blog/CategoryView,category,LINQ.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yXBfYwIlD5KQOPcHsH9JxnNP6CQ/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yXBfYwIlD5KQOPcHsH9JxnNP6CQ/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yXBfYwIlD5KQOPcHsH9JxnNP6CQ/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yXBfYwIlD5KQOPcHsH9JxnNP6CQ/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I want to follow up my &lt;a href="http://www.genericerror.com/blog/2009/01/21/LINQToNHibernateIEnumerableVsIQueryable.aspx"&gt;last&#xD;
post&lt;/a&gt; with a clear example showing what I expected to happen and why it didn't. &#xD;
What is the output of the following program?&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Program&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Main(&lt;span style="color: blue"&gt;string&lt;/span&gt;[]&#xD;
args)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt; bar&#xD;
= &lt;span style="color: blue"&gt;new&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt;();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt; foo&#xD;
= bar;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            foo.Say();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            bar.Say();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;virtual&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say()&#xD;
{ &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Foo"&lt;/span&gt;);&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;override&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say()&#xD;
{ &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Bar"&lt;/span&gt;);&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Anyone who has a decent grasp of inheritance and polymorphism should have correctly&#xD;
guessed that the output of the program is &lt;em&gt;BarBar&lt;/em&gt;.  The class &lt;em&gt;Bar&lt;/em&gt; overrides&#xD;
the default behaviour of &lt;em&gt;Foo&lt;/em&gt; and replaces it with something else.  What&#xD;
if we use extension methods?&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt; {}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt; {}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Extensions&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt; foo)&#xD;
{ &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Foo"&lt;/span&gt;);&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt; bar)&#xD;
{ &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Bar"&lt;/span&gt;);&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Because extension methods are a new addition to the framework people are more likely&#xD;
to get this wrong, like me.  The output of this program is &lt;em&gt;FooBar&lt;/em&gt;. &#xD;
The important difference is that the extension method on &lt;em&gt;Bar&lt;/em&gt; is not able&#xD;
to override and replace the default behaviour on &lt;em&gt;Foo&lt;/em&gt; and is only used if&#xD;
you refer to the object as a &lt;em&gt;Foo&lt;/em&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
If you're designing an API and want to avoid confusion, watch out for this one. &#xD;
As always there's workarounds, here's something you might try:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Extensions&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Foo&lt;/span&gt; foo)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;if&lt;/span&gt;(foo &lt;span style="color: blue"&gt;is&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt;)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
               &#xD;
((&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt;)foo).Say();&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            &lt;span style="color: blue"&gt;else&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
                &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Foo"&lt;/span&gt;);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
 &#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Say(&lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Bar&lt;/span&gt; bar)&#xD;
{ &lt;span style="color: #2b91af"&gt;Console&lt;/span&gt;.Write(&lt;span style="color: #a31515"&gt;"Bar"&lt;/span&gt;);&#xD;
}&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
This produces the same result as the original virtual method based program, &lt;em&gt;BarBar&lt;/em&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
While this might make you API a little more predictable it does so at the expense&#xD;
of the code.  Tying &lt;em&gt;Foo&lt;/em&gt; to it's derived classes like this starts to&#xD;
break down the reasons for using the &lt;em&gt;Foo &lt;/em&gt;abstraction in the first place and&#xD;
will make your code difficult to modify in future.  I would suggest these issues&#xD;
as the reason Microsoft didn't add a special case for &lt;em&gt;IQueryable&amp;lt;T&amp;gt;&lt;/em&gt; in &lt;em&gt;IEnumerable&amp;lt;T&amp;gt;.Where,&lt;/em&gt; but&#xD;
it turns out they have already added special cases for arrays and lists so who knows.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
It's the little details like this that make great interview questions for those annoying&#xD;
candidates that seem to know everything...&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=a80023c4-579f-42cd-b5f7-7e7656872a2a"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/rvV4X_sKGFA" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/01/23/VirtualMethodsVsExtensionMethods.aspx</feedburner:origLink></entry>
  <entry>
    <title>LINQ to NHibernate, IEnumerable vs IQueryable</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/3gfhyennO8E/LINQToNHibernateIEnumerableVsIQueryable.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,0cefe5a1-2e53-4dbd-a193-3fa03715cb80.aspx</id>
    <published>2009-01-21T03:35:46.66-08:00</published>
    <updated>2009-01-30T16:53:13.7937268-08:00</updated>
    <category term="Extension Methods" label="Extension Methods" scheme="http://www.genericerror.com/blog/CategoryView,category,ExtensionMethods.aspx" />
    <category term="LINQ" label="LINQ" scheme="http://www.genericerror.com/blog/CategoryView,category,LINQ.aspx" />
    <category term="NHibernate" label="NHibernate" scheme="http://www.genericerror.com/blog/CategoryView,category,NHibernate.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/S09ZyMYE9FDdSof4rEL_lL8Ts50/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S09ZyMYE9FDdSof4rEL_lL8Ts50/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/S09ZyMYE9FDdSof4rEL_lL8Ts50/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/S09ZyMYE9FDdSof4rEL_lL8Ts50/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I've been taking LINQ to NHibernate (&lt;a href="http://groups.google.com/group/nhusers/browse_thread/thread/b7a3f537f4cbf46d"&gt;Alpha&#xD;
just released&lt;/a&gt;) for a test drive in my latest project and so far I'm pleased enough&#xD;
that I think I will stick with it going forward.  This post is to point out a&#xD;
subtle behaviour that caught me unawares.  Consider the following example:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    session.Linq&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;Foo&lt;/span&gt;&amp;gt;()&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        .WithId(123)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        .Single();&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The first line is &lt;em&gt;LINQ to NHibernate&lt;/em&gt; speak which simply returns an &lt;em&gt;IQueryable&amp;lt;Foo&amp;gt;&lt;/em&gt; representing&#xD;
all available objects of type &lt;em&gt;Foo&lt;/em&gt;.  The important thing here is that&#xD;
it is just a query, the database has not been visited yet.  The second line is&#xD;
my own extension method which should extend the query and filter the results by Id:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;Foo&lt;/span&gt;&amp;gt;&#xD;
WithId(&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;Foo&lt;/span&gt;&amp;gt;&#xD;
foos, &lt;span style="color: blue"&gt;int&lt;/span&gt; id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;return&lt;/span&gt; foos.Where(x&#xD;
=&amp;gt; x.Id == id);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
The third line is a standard LINQ to SQL function which makes sure that there is only&#xD;
one item in the list and returns it for you.  This call is the first time that&#xD;
the code should touch the database and the result should be that only a single row&#xD;
is returned.  Unfortunately one of the tests I wrote today turned up something&#xD;
suspicious...  my extension method was being called 23 times and by coincidence&#xD;
there also happened to be 23 items in my database!&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Since the code actually produced the correct results and this was really a performance&#xD;
issue I decided it would be a good time to check out &lt;a href="http://nhprof.com/"&gt;Ayende's&#xD;
new NHibernate Profiler&lt;/a&gt;.  Overall I am quite impressed as it is easy to set&#xD;
up, shows me everything I expect and has a reasonably intuitive interface for a developer&#xD;
tool.  Compared to setting up a trace on the SQL server and trying to analyse&#xD;
the results, using the profiler was actually fun.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Now certain that my code was eagerly requesting every row in the table then throwing&#xD;
them away, I set out to figure out why.  Using the traditional &lt;em&gt;poke it with&#xD;
the debugger&lt;/em&gt; approach, I discovered that changing my extension method to this&#xD;
resolved the problem:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;static&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;Foo&lt;/span&gt;&amp;gt;&#xD;
WithId(&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;this&lt;/span&gt;&lt;span style="color: rgb(43,145,175)"&gt;IQueryable&lt;/span&gt;&amp;lt;&lt;span style="color: rgb(43,145,175)"&gt;Foo&lt;/span&gt;&amp;gt;&#xD;
foos, &lt;span style="color: blue"&gt;int&lt;/span&gt; id)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;return&lt;/span&gt; foos.Where(x&#xD;
=&amp;gt; x.Id == id);&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;p&gt;&#xD;
Why did I think &lt;em&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/em&gt; was a good choice?  Because &lt;em&gt;IQueryable&amp;lt;T&amp;gt;&lt;/em&gt; inherits&#xD;
directly from it and I was trying to use the less restrictive interface.  Why&#xD;
does it not work like I expect?  Because there is a &lt;em&gt;Where&lt;/em&gt; extension&#xD;
method for each of the interfaces and a quick look with Reflector shows that they&#xD;
do very, very different things.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Extension methods can't be overridden like virtual methods which means objects will&#xD;
act like the name you give them, not like what they really are.  This also means&#xD;
that it's not LINQ to NHibernate's fault at all, in fact you will likely run into&#xD;
this issue with LINQ to SQL as well.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
If there's a lesson to be learnt from this story it's probably to be more careful&#xD;
of extension methods.  I can't really call my own misunderstandings bugs in the&#xD;
framework so instead I'm just going to make some snarky remarks about un-intuitive&#xD;
behaviour and sign off...&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=0cefe5a1-2e53-4dbd-a193-3fa03715cb80"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/3gfhyennO8E" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/01/21/LINQToNHibernateIEnumerableVsIQueryable.aspx</feedburner:origLink></entry>
  <entry>
    <title>From ASP.Net Webforms to MVC</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/_fPdqDKyhKI/FromASPNetWebformsToMVC.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,4d037e80-3f3a-47b2-9be6-c34f381b0c9a.aspx</id>
    <published>2009-01-15T02:20:39.0475351-08:00</published>
    <updated>2009-01-15T02:20:39.0475351-08:00</updated>
    <category term="ASP.Net" label="ASP.Net" scheme="http://www.genericerror.com/blog/CategoryView,category,ASPNet.aspx" />
    <category term="MVC" label="MVC" scheme="http://www.genericerror.com/blog/CategoryView,category,MVC.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/mjx_edUUsuHQhw5QvWFWOyIVAQs/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mjx_edUUsuHQhw5QvWFWOyIVAQs/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/mjx_edUUsuHQhw5QvWFWOyIVAQs/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/mjx_edUUsuHQhw5QvWFWOyIVAQs/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
This post outlines some of my experiences moving from ASP.Net web forms to the new &lt;a href="http://www.asp.net/mvc/"&gt;ASP.Net&#xD;
MVC framework&lt;/a&gt; coming from Microsoft.  There is plenty of talk about all the&#xD;
advantages of the new framework but it comes at a price.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Should You Use It?&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
The Microsofties are being quite clear that the new framework isn't for everyone and&#xD;
that the old one isn't going away.  I still use both and which one is better&#xD;
is way too subjective for anyone but you to answer.  Many of my projects will&#xD;
continue to use the old model, particularly if the project sounds like this:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Small project.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Few technical challenges.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Lots of content, little functionality.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Fast delivery is a priority.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Low budget is a priority.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Existing web forms based CMS.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Team not experienced with MVC.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
This describes a lot of the quick marketing style sites that I do.  For some&#xD;
of my new projects I'm moving the the new MVC framework.  There is a large gray&#xD;
area in between but I will prefer the new framework for the following sorts of projects:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Large project.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Quality is a priority.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Difficult technical problems to solve.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Integration with external systems.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
The code base is expected to live for several years.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
The code will be reused or deployed in many places.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Experienced team or one willing to invest time learning.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
Now before I make anyone angry, yes you can do a great job of large complex projects&#xD;
using the web forms model, I just hate doing it.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Learning Curve&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
If you're like me and you've never worked with a similar framework before (for example &lt;a href="http://www.castleproject.org/MonoRail/"&gt;MonoRail&lt;/a&gt; or &lt;a href="http://rubyonrails.org/"&gt;Rails&lt;/a&gt;)&#xD;
you're suddenly going to find yourself very unproductive as you relearn how to do&#xD;
all the things you've been doing for years in web forms.  Here are some of the&#xD;
things you will want to spend time on:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Learning the key architecture concepts in the framework.  You will need a solid&#xD;
understanding of how a URL makes its way through routing, a controller and finally&#xD;
the view.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Form input and validation is very different to what you are used to.  Spend time&#xD;
coming up with some patterns you like.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Postbacks and viewstate no longer exist as you knew them.  You can still do similar&#xD;
things but it will be a bit more manual than you are used to.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
You need to understand more about how HTML and HTTP work.  Details such as the&#xD;
difference between GET and POST become important.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Many of the existing controls you use are not going to suit the MVC model.  As&#xD;
well as the usual display controls this is going to affect things like AJAX.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;p&gt;&#xD;
Expect to spend a couple of weeks before you are really comfortable working with the&#xD;
new framework.  The good news is that once you figure these things out you will&#xD;
be back to your old self again.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;What Helps?&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
The new framework isn't really based on new ideas.  In fact it's really built&#xD;
on tried and tested concepts, even if they are new to the average Microsoft developer. &#xD;
Here are some things from my past experience that help ease my transition:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
Knowing ASP.Net and IIS very well.  Most of your knowledge about these technologies&#xD;
will still be useful.  Though you wont be using web forms you will still have&#xD;
the other ASP.Net features to work with such as session state and output caching.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Experience with unit testing.  One of the key goals on the new framework is testability&#xD;
and if you aren't doing it you're probably missing out on a lot of the advantages. &#xD;
Unit testing can be tough to pick up in a hurry so any knowledge will help.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
Familiarity with domain driven design.  I had already been working with patterns&#xD;
for a strong domain model distinctly separate from the user interface.  Most&#xD;
of my existing work in this area carried over very smoothly.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
jQuery (or your JavaScript library of choice).  It will definitely help if you're&#xD;
used to getting your hands dirty with JavaScript as you will find yourself building&#xD;
many features from scratch, features web forms has out of the box.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;h4&gt;Working With Beta Bits&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
The framework is still in beta so it's not done and there will be changes.  The&#xD;
core feels very solid and I haven't encountered any major bugs that have stopped me. &#xD;
More importantly realise that there is not yet good support from third party libraries&#xD;
to fill in the holes so things feel very bare bones in a lot of cases.  One of&#xD;
the few resources out there is the &lt;a href="http://www.codeplex.com/MVCContrib"&gt;MVC&#xD;
Contrib&lt;/a&gt; library.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Because the framework has already had 6 releases (5 previews, 1 beta) with breaking&#xD;
changes most of the information in blogs and forums is out of date and wont work exactly&#xD;
as described.  Finding information on how things are now can be tricky and keeping &lt;a href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/a&gt; nearby&#xD;
is recommended.  The best information is still in &lt;a href="http://weblogs.asp.net/scottgu/archive/2008/10/16/asp-net-mvc-beta-released.aspx"&gt;Scott&#xD;
Gu's blog&lt;/a&gt;.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Freedom&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
I'm starting to settle in with MVC and it feels good.  My XHTML validates as&#xD;
strict and I haven't had to do anything remotely resembling a hack or fudge. &#xD;
The framework is extensible in so many ways that web forms isn't so the few things&#xD;
I haven't liked I've been able to change.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Yes, it's worth it.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=4d037e80-3f3a-47b2-9be6-c34f381b0c9a"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/_fPdqDKyhKI" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2009/01/15/FromASPNetWebformsToMVC.aspx</feedburner:origLink></entry>
  <entry>
    <title>ASP.Net Session ID Changes Every Request</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/7vR8e1DhUqA/ASPNetSessionIDChangesEveryRequest.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,d2cba3ce-ad09-48e2-a5b2-4d901b2dd3ec.aspx</id>
    <published>2008-12-13T22:37:53.6237108-08:00</published>
    <updated>2008-12-13T22:37:53.6237108-08:00</updated>
    <category term="ASP.Net" label="ASP.Net" scheme="http://www.genericerror.com/blog/CategoryView,category,ASPNet.aspx" />
    <category term="Session" label="Session" scheme="http://www.genericerror.com/blog/CategoryView,category,Session.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/93LuxNqQHItr5NZ4tBP_Vydymas/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/93LuxNqQHItr5NZ4tBP_Vydymas/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/93LuxNqQHItr5NZ4tBP_Vydymas/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/93LuxNqQHItr5NZ4tBP_Vydymas/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
Just a small note on a problem I just had.  ASP.Net provides an &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.sessionstate.httpsessionstate.sessionid.aspx"&gt;ID&#xD;
for the current session&lt;/a&gt; which can be especially useful for tracking statistics&#xD;
about the user.  Normally you expect all requests from a single user to come&#xD;
in with the same session ID however that was not the behaviour I was seeing today.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
It turns out that unless you make a change to the session data, the session will not&#xD;
be persisted and a new one will be generated for the next request.  Something&#xD;
like this placed in you Global.asax file should do the trick:&#xD;
&lt;/p&gt;&#xD;
        &lt;div style="font-size: 10pt; background: white; color: black; font-family: courier new"&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    &lt;span style="color: blue"&gt;public&lt;/span&gt;&lt;span style="color: blue"&gt;class&lt;/span&gt;&lt;span style="color: #2b91af"&gt;Global&lt;/span&gt; : &lt;span style="color: #2b91af"&gt;HttpApplication&lt;/span&gt;&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
    {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        &lt;span style="color: blue"&gt;protected&lt;/span&gt;&lt;span style="color: blue"&gt;void&lt;/span&gt; Session_Start(&lt;span style="color: blue"&gt;object&lt;/span&gt; sender, &lt;span style="color: #2b91af"&gt;EventArgs&lt;/span&gt; e)&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        {&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
            Session[&lt;span style="color: #a31515"&gt;"PersistMe"&lt;/span&gt;]&#xD;
= &lt;span style="color: blue"&gt;true&lt;/span&gt;;&#xD;
&lt;/p&gt;&#xD;
          &lt;p style="margin: 0px"&gt;&#xD;
        }&#xD;
&lt;/p&gt;&#xD;
        &lt;/div&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=d2cba3ce-ad09-48e2-a5b2-4d901b2dd3ec"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/7vR8e1DhUqA" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2008/12/14/ASPNetSessionIDChangesEveryRequest.aspx</feedburner:origLink></entry>
  <entry>
    <title>First Steps With NDepend</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/GenericError/~3/pmBI-3BszZQ/FirstStepsWithNDepend.aspx" />
    <id>http://www.genericerror.com/blog/PermaLink,guid,b2a2a0da-303d-449a-9229-57a6303e0797.aspx</id>
    <published>2008-12-04T19:11:18.9515445-08:00</published>
    <updated>2008-12-04T19:11:18.9515445-08:00</updated>
    <category term="NDepend" label="NDepend" scheme="http://www.genericerror.com/blog/CategoryView,category,NDepend.aspx" />
    <category term="Tools" label="Tools" scheme="http://www.genericerror.com/blog/CategoryView,category,Tools.aspx" />
    <content type="html">
&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/yVCchESPAxVdOydbDOOQi7PS7Ps/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yVCchESPAxVdOydbDOOQi7PS7Ps/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/yVCchESPAxVdOydbDOOQi7PS7Ps/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/yVCchESPAxVdOydbDOOQi7PS7Ps/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;div xmlns="http://www.w3.org/1999/xhtml"&gt;&#xD;
        &lt;p&gt;&#xD;
I've just downloaded NDepend for the first time and I'm going to make notes here as&#xD;
I work my way through it.  Please note that I'm a complete beginner with the&#xD;
tool so this is first impressions only, not a comprehensive review.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I've heard lots about the tool and seen lots of interesting posts on what it does,&#xD;
but have never really been sure if it would give me any value.  My first concern&#xD;
looking through &lt;a href="http://codebetter.com/blogs/patricksmacchia/default.aspx"&gt;Patrick's&#xD;
blog&lt;/a&gt; is that there are a lot of crazy numbers, graphs and blobs of something going&#xD;
on.  It doesn't seem very approachable at first glance, let's see how it works&#xD;
out.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The .zip file doesn't contain an installer which always makes me wonder where to put&#xD;
it, I'm not sure if that's a good or a bad thing.  I watched &lt;a href="http://s3.amazonaws.com/NDependOnlineDemos/GettingStarted_viewlet_swf.html"&gt;a&#xD;
quick demo&lt;/a&gt; but I like to dive right in so I'm ignoring the documentation for now. &#xD;
I've got a nice small project I've recently started so I'll drop in the .exe and see&#xD;
what it says...&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;Stuff, Lots Of It!&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
Loading my .exe I get a screen filled with lots of, er, &lt;a href="http://www.ndepend.com/Screenshots.aspx"&gt;stuff&lt;/a&gt;. &#xD;
I should point out that I'm not looking for any particular piece of information here,&#xD;
I'm looking to see what the tool can do for me and apparently that's a lot. &#xD;
Having a quick scan around I see this in the lower right:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/FirstStepsWithNDepend_D215/NDepend_2.png"&gt;&#xD;
            &lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="250" alt="NDepend" src="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/FirstStepsWithNDepend_D215/NDepend_thumb.png" width="444" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
That's surprising.  I don't comment very heavily so I would expect a lot more&#xD;
complaints!  Apparently the filter ignores small methods which makes sense. &#xD;
Opening up the method in Visual Studio shows that it doesn't have any comments at&#xD;
all.  A quick refactor breaks the method in two using the method name to explain&#xD;
what's going on.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
I jump back to NDepend to see what it says but have a mouse spasm and drag one of&#xD;
the many panels out of place and can't figure out how to get it back where it was. &#xD;
Fortunately the &lt;em&gt;View&lt;/em&gt; menu comes to the rescue with &lt;em&gt;Reset Views&lt;/em&gt;. &#xD;
I run the analysis again and it takes 15 seconds, which seems a bit long for such&#xD;
a small project, but being in a malnourished VM it's not a very fair measurement.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
The warning is gone, my code is cleaner, one point for NDepend.&#xD;
&lt;/p&gt;&#xD;
        &lt;h4&gt;CQL Queries&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
I take NDepend's point back for the bad pun, this panel looks interesting though:&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
          &lt;a href="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/FirstStepsWithNDepend_D215/CQL_2.png"&gt;&#xD;
            &lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="300" alt="CQL" src="http://www.genericerror.com/blog/content/binary/WindowsLiveWriter/FirstStepsWithNDepend_D215/CQL_thumb.png" width="553" border="0"&gt;&lt;/img&gt;&#xD;
          &lt;/a&gt;&#xD;
        &lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
This looks a lot like &lt;a href="http://msdn.microsoft.com/en-us/library/bb429476.aspx"&gt;FxCop&lt;/a&gt; and&#xD;
many of the rules are the same.  Looking through the rules it seems I'm going&#xD;
to need to customise them heavily to suit my code, the first things I see are:&#xD;
&lt;/p&gt;&#xD;
        &lt;ul&gt;&#xD;
          &lt;li&gt;&#xD;
It complains that all my WPF controls are too big, not much I can do about that.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
It wants to mark protected, internal or private a bunch of methods I expose for unit&#xD;
testing.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
It wants to name all my instance variables with the dreaded &lt;em&gt;m_&lt;/em&gt;.&lt;/li&gt;&#xD;
          &lt;li&gt;&#xD;
It wants me to seal all my classes, maybe I should but no one else is using this and&#xD;
I just don't care.&lt;/li&gt;&#xD;
        &lt;/ul&gt;&#xD;
        &lt;h4&gt;Back To Work&#xD;
&lt;/h4&gt;&#xD;
        &lt;p&gt;&#xD;
My &lt;a href="http://www.ndepend.com/Res/NDependBig02.PNG"&gt;dependency matrix&lt;/a&gt; is&#xD;
far to small to be interesting at this stage so I'm not spending any time with it,&#xD;
everything seems good so far though.  There's this crazy thing with the &lt;a href="http://www.ndepend.com/Res/Poster800x800Big.PNG"&gt;blobs&lt;/a&gt; but&#xD;
it's hard to see what it actually tells me and I only have 30 or so blobs so it can&#xD;
wait.  I've got features to build so that's all for today.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
First impressions?  There's a lot here and it's going to take time to figure&#xD;
it all out.  I can see real value in using it to maintain the quality of large&#xD;
code bases, especially where teams are involved.  For the little project I'm&#xD;
working on right now it's a lot to take in and I don't know if it will work out, perhaps&#xD;
it will just help keep me honest for the moment.&#xD;
&lt;/p&gt;&#xD;
        &lt;p&gt;&#xD;
Next time I want to clean up those CQL queries to see if I can get all the lights&#xD;
to go green, then maybe see if I can get something useful out of those... blobs.&#xD;
&lt;/p&gt;&#xD;
        &lt;img width="0" height="0" src="http://www.genericerror.com/blog/aggbug.ashx?id=b2a2a0da-303d-449a-9229-57a6303e0797"&gt;&lt;/img&gt;&#xD;
      &lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/GenericError/~4/pmBI-3BszZQ" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://www.genericerror.com/blog/2008/12/05/FirstStepsWithNDepend.aspx</feedburner:origLink></entry>
</feed>
