<feed 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/" xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
    <title>X</title>
    <link rel="self" type="application/xml" href="http://geekswithblogs.net/cskardon/Atom.aspx" />
    <subtitle type="html">Coder, not artist.</subtitle>
    <id>http://geekswithblogs.net/cskardon/Default.aspx</id>
    <author>
        <name>Chris Skardon</name>
        <uri>http://geekswithblogs.net/cskardon/Default.aspx</uri>
    </author>
    <generator uri="http://subtextproject.com" version="Subtext Version 0.0.0.0">Subtext</generator>
    <updated>2012-02-06T21:12:20Z</updated>
    <entry>
        <title>Mocking ITable&amp;lt;T&amp;gt;</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/02/06/mocking-itablelttgt.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/02/06/mocking-itablelttgt.aspx</id>
        <published>2012-02-06T21:12:20-12:00:00</published>
        <updated>2012-02-06T21:12:20Z</updated>
        <content type="html">&lt;p&gt;I have to do some mocking of an &lt;a title="ITable on MSDN" href="http://msdn.microsoft.com/en-us/library/system.data.linq.itable.aspx" target="_blank"&gt;ITable&lt;/a&gt; to be able to test some of my code, as you may imagine this is the point where we’re crossing the data boundary… Now, ITable is a total bugger to mock, I’ve tried on (at least) 3 separate occasions to get it mocked, and have only now, finally achieved an 80% solution.&lt;/p&gt;  &lt;p&gt;(Nothing is ever 100%)&lt;/p&gt;  &lt;p&gt;I’m not using any mock framework, they just take too long to setup (&lt;em&gt;in this case&lt;/em&gt;) and instead have a concrete class that implements ITable and uses an &lt;a href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx" target="_blank"&gt;IList&lt;/a&gt; as it’s base.&lt;/p&gt;  &lt;p&gt;Without further ado:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Data.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;
&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq.Expressions;

&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MockTable&amp;lt;T&amp;gt; : ITable&amp;lt;T&amp;gt; &lt;span class="kwrd"&gt;where&lt;/span&gt; T : &lt;span class="kwrd"&gt;class&lt;/span&gt;
{
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; IList&amp;lt;T&amp;gt; _entities;

    &lt;span class="kwrd"&gt;public&lt;/span&gt; MockTable(IList&amp;lt;T&amp;gt; entities)
    {
        _entities = entities;
    }

    &lt;span class="preproc"&gt;#region&lt;/span&gt; ITable&amp;lt;T&amp;gt; Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerator&amp;lt;T&amp;gt; GetEnumerator()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; GetEnumerator();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Expression Expression 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().Expression; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; Type ElementType 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().ElementType; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; IQueryProvider Provider 
    { 
        get 
        { 
            &lt;span class="kwrd"&gt;return&lt;/span&gt; _entities.AsQueryable().Provider; 
        } 
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; InsertOnSubmit(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Attach(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; DeleteOnSubmit(T entity)
    {
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; NotImplementedException();
    }
    &lt;span class="preproc"&gt;#endregion&lt;/span&gt; ITable&amp;lt;T&amp;gt; Members
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;To use, in your test, let’s say you have an IDataContext (and why not) looking like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IDataContext
{
    ITable&amp;lt;Person&amp;gt; People { get; set; }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;You can then mock this interface like so:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;[TestMethod]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Something_DoesSomething_WhenSomething()
{
    &lt;span class="rem"&gt;//Create seed list&lt;/span&gt;
    var people = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Person&amp;gt;{ &lt;span class="kwrd"&gt;new&lt;/span&gt; Person{Name = &lt;span class="str"&gt;"Chris Skardon"&lt;/span&gt;} };
    
    &lt;span class="rem"&gt;//Create new Mock&lt;/span&gt;
    var dataContextMock = &lt;span class="kwrd"&gt;new&lt;/span&gt; Mock&amp;lt;IDataContext&amp;gt;();
    
    &lt;span class="rem"&gt;//Setup the People ITable property&lt;/span&gt;
    dataContextMock
        .Setup(dc =&amp;gt; dc.People)
        .Returns(&lt;span class="kwrd"&gt;new&lt;/span&gt; MockTable&amp;lt;Person&amp;gt;(people));
    
    &lt;span class="rem"&gt;/* Asserts etc */&lt;/span&gt;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;It’s obviously not perfect, I haven’t bothered with several methods, but I’ll get to them later…&lt;/p&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148621.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148621.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148621.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148621.aspx</trackback:ping>
    </entry>
    <entry>
        <title>CSharpCodeDomClientCodeGenerator encountered a fatal exception</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/01/23/csharpcodedomclientcodegenerator-encountered-a-fatal-exception.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/01/23/csharpcodedomclientcodegenerator-encountered-a-fatal-exception.aspx</id>
        <published>2012-01-23T22:00:14-12:00:00</published>
        <updated>2012-01-23T22:00:14Z</updated>
        <content type="html">&lt;p&gt;I’ve been battling this now for an hour or so, and as all the reponses I’ve seen online haven’t really helped, I thought I’d whack this up..&lt;/p&gt;  &lt;p&gt;The error I got was:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;The code generator 'Microsoft.ServiceModel.DomainServices.Tools.CSharpCodeDomClientCodeGenerator' encountered a fatal exception and could not generate code for project 'TheProject.csproj':     &lt;br /&gt;Exception has been thrown by the target of an invocation.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now, searching online comes up with loads of things, but the most important one I found was on &lt;a href="http://connect.microsoft.com/VisualStudio/feedback/details/662780/exception-thrown-by-the-target-of-an-invocation-in-microsoft-ria-client-targets" target="_blank"&gt;Microsoft Connect&lt;/a&gt;. It’s actually a comment from ArielBH, which says:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;From my exprience it is connected to the DataAnnotions attributes when it is looking for types in the resx.     &lt;br /&gt;When I tried to manipulate the Buisness Applocation template and move Ria Services link and files to other assembly I had the same issue. When I removed all references to those resx files this issue disappered.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I indeed have a class using DataAnnotations linking to a resx file… So, I removed all the attributes linking to the resx files, (i.e. removing all the validation…) and did another compile…&lt;/p&gt;  &lt;p&gt;At this point RIA decides to actually give the correct error, that a method was missing… &lt;/p&gt;  &lt;p&gt;So, point of note is that the DataAnnotations will mask the actual error, but once you’ve fixed the error, putting the DataAnnotations back will be fine…&lt;/p&gt;  &lt;p&gt;Grrrr&lt;/p&gt; &lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148458.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148458.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148458.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148458.aspx</trackback:ping>
    </entry>
    <entry>
        <title>InitParams in Silverlight &amp;ndash; passed via MVC</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2012/01/06/initparams-in-silverlight-ndash-passed-via-mvc.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2012/01/06/initparams-in-silverlight-ndash-passed-via-mvc.aspx</id>
        <published>2012-01-06T00:40:53-12:00:00</published>
        <updated>2012-01-06T00:40:53Z</updated>
        <content type="html">&lt;p&gt;The old skool way of passing InitParams in aspx is well documented, adding a:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="initParams"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="&amp;lt;%=InitParams%&amp;gt;"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;which is accessing the public ‘InitParams’ &lt;em&gt;member&lt;/em&gt; in the code-behind file, which is inevitably set up via the ‘Page_Init’ handler.&lt;/p&gt;

&lt;p&gt;All well and good, but not practical in MVC, so… how to do this?&lt;/p&gt;

&lt;p&gt;(NB. This is just how I’ve done it, it’s not the only solution)&lt;/p&gt;

&lt;p&gt;There are a few things to change:&lt;/p&gt;

&lt;h2&gt;1. The Model&lt;/h2&gt;

&lt;p&gt;I’ve created a SilverlightHostModel, it only has one property in it (at the moment), to hold the InitParams:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Webby.Models
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; SilverlightHostModel
    {
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; InitParams { get; set; }
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;2. The Controller&lt;/h2&gt;

&lt;p&gt;The controller is going to create the model and pass it to the view..&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ViewResult Ria()
{
    SilverlightHostModel host = &lt;span class="kwrd"&gt;new&lt;/span&gt; SilverlightHostModel();
    host.InitParams = &lt;span class="str"&gt;"IpAddress="&lt;/span&gt; + System.Web.HttpContext.Current.Request.ServerVariables[&lt;span class="str"&gt;"REMOTE_ADDR"&lt;/span&gt;];

    &lt;span class="kwrd"&gt;return&lt;/span&gt; View(host);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;3. The View&lt;/h2&gt;

&lt;p&gt;The view needs to be strongly-typed to the Model, so we add this to the top of the new view:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;@model Webby.Models.SilverlightHostModel&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;and where we’re hosting the &lt;a href="http://www.silverlight.net"&gt;Silverlight&lt;/a&gt; control itself, we change the param to read:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;param&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="initParams"&lt;/span&gt; &lt;span class="attr"&gt;value&lt;/span&gt;&lt;span class="kwrd"&gt;="@Model.InitParams"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;h2&gt;4. The App.xaml.cs Application_Startup&lt;/h2&gt;

&lt;p&gt;You (I presume) already have this done, but you would get your new parameter like so&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Application_Startup(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, StartupEvents e)
{
    &lt;span class="rem"&gt;//Get the ip address from InitParams&lt;/span&gt;
    &lt;span class="kwrd"&gt;string&lt;/span&gt; ip = e.InitParams[&lt;span class="str"&gt;"IpAddress"&lt;/span&gt;];

    &lt;span class="kwrd"&gt;this&lt;/span&gt;.RootVisual = &lt;span class="kwrd"&gt;new&lt;/span&gt; MainPage();
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Done!&lt;/p&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/148259.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/148259.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/148259.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/148259.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Ajaxy</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/11/10/ajaxy.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/11/10/ajaxy.aspx</id>
        <published>2011-11-10T08:16:05-12:00:00</published>
        <updated>2011-11-10T08:16:05Z</updated>
        <content type="html">&lt;p&gt;Today is the big day, the day I attempt to use Ajax in the app… &lt;/p&gt;  &lt;p&gt;I’ve never done this (well, tell a lie, I’ve done it in a ‘tutorial’ site, but that was a while ago now), so it’s going to be interesting.. &lt;/p&gt;  &lt;p&gt;OK, basics first, let’s start with the @Ajax.ActionLink&lt;/p&gt;  &lt;p&gt;Right, first stab:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@Ajax.ActionLink(&lt;span class="str"&gt;"Click to get latest"&lt;/span&gt;,
                 &lt;span class="str"&gt;"LatestEntry"&lt;/span&gt;,
                 &lt;span class="kwrd"&gt;new&lt;/span&gt; AjaxOptions
                   {
                      UpdateTargetId = &lt;span class="str"&gt;"ajaxEntrant"&lt;/span&gt;,
                      InsertionMode = InsertionMode.Replace,
                      HttpMethod = &lt;span class="str"&gt;"GET"&lt;/span&gt;
                   })&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;As far as I’m aware, I’m asking to get the ‘LatestEntry’ from the current controller, and in doing so, I will replace the #ajaxEntrant DOM bit with the result. So. I guess I’d better get the result working…&lt;/p&gt;

&lt;p&gt;To the controller!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; PartialResult LatestEntry()
{
    var entrant =_db.Entrants.OrderByDescending(e =&amp;gt; e.Id).Single();
    &lt;span class="kwrd"&gt;return&lt;/span&gt; PartialView(&lt;span class="str"&gt;"_Entrant"&lt;/span&gt;, entrant);
}&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Pretty simple, just returns the last entry in a PartialView… but! I have yet to make my partial view, so onto that!&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@model Webby.Entrant

&amp;lt;div &lt;span class="kwrd"&gt;class&lt;/span&gt;=&lt;span class="str"&gt;"entrant"&lt;/span&gt;&amp;gt;
    &amp;lt;h4&amp;gt;@Model.Name&amp;lt;/h4&amp;gt;
&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Again, super simple, (I’m really just testing at this point)…&lt;/p&gt;

&lt;p&gt;All the code is now there (&lt;em&gt;as far as I know&lt;/em&gt;), so F5 and in… &lt;/p&gt;

&lt;p&gt;And once again, in the traditionally disappointing way of the norm, it doesn’t work, sure… it &lt;em&gt;opens&lt;/em&gt; the right view, but it doesn’t replace the #ajaxEntry DOM element, rather it replaces the whole page… The source code (again, as far as I know) looks ok:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt; &lt;span class="attr"&gt;data-ajax&lt;/span&gt;&lt;span class="kwrd"&gt;="true"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-method&lt;/span&gt;&lt;span class="kwrd"&gt;="GET"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-mode&lt;/span&gt;&lt;span class="kwrd"&gt;="replace"&lt;/span&gt; &lt;span class="attr"&gt;data-ajax-update&lt;/span&gt;&lt;span class="kwrd"&gt;="#ajaxEntrants"&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/Entrants/LatestEntrant"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Click to get latest&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;a&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Changing the InsertionMode to any of the other modes has the same effect..&lt;/p&gt;

&lt;p&gt;It’s not the DOM name either, changing that has the same effect.. i.e. none.&lt;/p&gt;

&lt;p&gt;It’s not the partial view either, just making that a &amp;lt;p&amp;gt; has (&lt;em&gt;again&lt;/em&gt;) no effect…&lt;/p&gt;

&lt;p&gt;Ahhhhh --- what a schoolboy error… I had neglected (ahem) to actually put the script bit into the calling page (another save from &lt;a href="http://stackoverflow.com/questions/4557021/mvc-3-ajax-load-partial-view-into-div"&gt;stackoverflow&lt;/a&gt;):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="@Url.Content("&lt;/span&gt;~/&lt;span class="attr"&gt;Scripts&lt;/span&gt;/&lt;span class="attr"&gt;jquery&lt;/span&gt;.&lt;span class="attr"&gt;unobtrusive-ajax&lt;/span&gt;.&lt;span class="attr"&gt;js&lt;/span&gt;&lt;span class="kwrd"&gt;")"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;I’ve now stuck that into the _Layout.cshtml view &lt;em&gt;temporarily&lt;/em&gt; to aid the development process… :) &lt;/p&gt;

&lt;p&gt;Onwards and upwards!&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;a title="Chris Skardon is on Google+" href="http://plus.google.com/101339052790440625852/about" rel="author" alt="Google+"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147649.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147649.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147649.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147649.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Comprehensive redesigns</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/11/09/comprehensive-redesigns.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/11/09/comprehensive-redesigns.aspx</id>
        <published>2011-11-09T07:23:06-12:00:00</published>
        <updated>2011-11-09T07:23:06Z</updated>
        <content type="html">&lt;p&gt;So, last night I realised that I’d made some bad decisions with the database, structure and naming, so… I’ve now refactored it all, and I’m feeling… hmmm… meh about it. I suspect I will redo it all later, but for now it will do….&lt;/p&gt;  &lt;p&gt;I’ve also come to the conclusion that I was maybe trying too much for the initial release, so as a consequence I have removed one part of the project… (which, by-the-by, I intend to have published in a month or so – and yes Andy, that is one month longer than I mentioned to you in that email :)) &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;@Html.DisplayFor()&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I find myself using DisplayFor a lot at the moment, is this correct? I mean – it works, but is that really only for forms? Do I need to use it? &lt;em&gt;Should&lt;/em&gt; I use it?&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147635.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147635.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147635.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147635.aspx</trackback:ping>
    </entry>
    <entry>
        <title>Registering&amp;hellip;</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/10/26/registeringhellip.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/10/26/registeringhellip.aspx</id>
        <published>2011-10-26T08:50:53-12:00:00</published>
        <updated>2011-10-27T20:02:39Z</updated>
        <content type="html">&lt;p&gt;So, I want potential clients to have to enter the least amount of info possible to get an account, to that end, I really don’t see the benefit of a username &lt;em&gt;and&lt;/em&gt; email address, I’d rather just use the email address.&lt;/p&gt;
&lt;p&gt;Pretty easy, edit the Register.cshtml to remove all traces of a ‘username’ field…&lt;/p&gt;
&lt;p&gt;Edit the controller so that it now reads:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;
   model.UserName = model.Email;
   &lt;span class="kwrd"&gt;if&lt;/span&gt; (ModelState.IsValid) { &lt;span class="rem"&gt;/*...*/&lt;/span&gt; }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;F5 and … no&lt;/p&gt;
&lt;p&gt;Hmmm, turns out the ModelState isn’t valid, and that’s down to the fact that I’ve left in the ‘Required’ bit on the UserName property in the AccountModels RegisterModel class.&lt;/p&gt;
&lt;pre class="csharpcode"&gt;
    &lt;span class="rem"&gt;//[Required]&lt;/span&gt;
    [Display(Name = &lt;span class="str"&gt;"User name"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; UserName { get; set; }&lt;/pre&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;style type="text/css"&gt;&lt;![CDATA[
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;
&lt;p&gt;Conceivably, I don’t really need that property at all, and can probably just do away with it later, but for now it can remain… Bigger fish to fry and all that…&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;a title="Chris Skardon is on Google+" alt="Google+" rel="author" href="http://plus.google.com/101339052790440625852/about"&gt;Chris&lt;/a&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147468.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147468.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147468.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147468.aspx</trackback:ping>
    </entry>
    <entry>
        <title>MVC&amp;ndash;Day 2(or 3/4ish, maybe more)</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/10/13/mvcndashday-2or-34ish-maybe-more.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/10/13/mvcndashday-2or-34ish-maybe-more.aspx</id>
        <published>2011-10-13T06:46:30-12:00:00</published>
        <updated>2011-10-13T06:46:30Z</updated>
        <content type="html">&lt;p&gt;So, my excursion in the web world continues… One of the issues I have coming from silverlight / wpf is that I’m very used to the XAML, MVVM approach to developing, I can knock up a passable interface in XAML in very little time (note, I didn’t say a &lt;em&gt;good&lt;/em&gt; interface), but I really don’t know how to do this in CSS.. &lt;/p&gt;  &lt;p&gt;OK, not totally true, I have a rough guess, I have played with things like Firebug, and modified existing css in the past, but the problem with that, is that I’m just tinkering.&lt;/p&gt;  &lt;p&gt;With this site, I want to learn CSS properly, from scratch, I will use the existing site.css (which is now renamed to SitOrige.css due to a ‘touchpad’ fat thumb incident in my rename attempt) to see how some things are done, but as it stands my site is now the plain html that (I presume) a screen reader should see, and I intend to get to grips with the looks soon.&lt;/p&gt;  &lt;p&gt;Of course having done that I’m now painfully aware that without content, style is a bit pointless, sooo, on with content… I currently have 6 Controllers, (including the default Account and Home controller) the other four at present representing four of the entities I have. I don’t know if this is right, at the moment it seems like a bit of overkill, but that could be because I’ve implemented the Add/Edit/Delete bit in each controller, I guess with time I will strip those down to bare bones, buuut for now it’ll do.&lt;/p&gt;  &lt;p&gt;I’m pretty happy (although I realise this is noddy stuff) that my links are working and I’ve actually done some Razor code hooking my entities together, and the ease of this has been very unexpected. The biggest issue I’ve had so far was when I was attempting to jump from one controller to another, I was naively using:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;@Html.ActionLink(item.Name, &lt;span class="str"&gt;"Details"&lt;/span&gt;, &lt;span class="str"&gt;"Controller2"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; {item.Id})&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;When I should have been using:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;@Html.ActionLink(item.Name, &lt;span class="str"&gt;"Details"&lt;/span&gt;, &lt;span class="str"&gt;"Controller2"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; {item.Id}&lt;strong&gt;, &lt;span class="kwrd"&gt;null&lt;/span&gt;&lt;/strong&gt;)&lt;/pre&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;That took a bit of stack overflowing to work out..&lt;/p&gt;

&lt;p&gt;My plan forward is to try to add a bit of interactivity, I have some ‘auto-generation’ code to add some stuff into the site which I’d like to get running, at present it’s in a console app and appears to be working ok, so fingers crossed it won’t prove to be too onerous.&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147294.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147294.aspx</wfw:comment>
        <slash:comments>4</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147294.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147294.aspx</trackback:ping>
    </entry>
    <entry>
        <title>MVC3&amp;ndash;The Beginning</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/10/11/mvc3ndashthe-beginning.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/10/11/mvc3ndashthe-beginning.aspx</id>
        <published>2011-10-11T07:56:41-12:00:00</published>
        <updated>2011-10-11T07:56:41Z</updated>
        <content type="html">&lt;p&gt;OOook, those who know me, or have read my blog probably have a pretty good idea that I’m a silverlight, wpf, wcf, c#, xamly kinda guy. I’ve never really done anything webby, the closest I’ve gotten is doing a bit of backend stuff, well, times change, and quite frankly I wanted to do something new… soooo&lt;/p&gt;  &lt;p&gt;I’ve opted to go down the MVC route, for two main reasons – 1, I figured I may as well learn a good framework, 2, Matt Abbott told me that MVC lets you get dirty with HTML, and that’s one of the things I want to learn! It’s important to note..&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font color="#c0504d"&gt;I have &lt;em&gt;no&lt;/em&gt; experience in HTML / CSS / JavaScript, so this is a windows developer going into the world of web.&lt;/font&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;I’ve actually been looking at this for a bit now, and I don’t really want to go too far back over what I’ve done, but, to get up to speed I have watched the PluralSight MVC course on &lt;a href="http://www.asp.net/mvc"&gt;www.asp.net/mvc&lt;/a&gt; and gone through the &lt;a href="http://mvcmusicstore.codeplex.com/"&gt;Music Store&lt;/a&gt; example project on CodePlex.&lt;/p&gt;  &lt;p&gt;As it stands, architecturally, I think I’m in an ok stead, the coding looks to be ok, but I fear I will become massively unstuck with the CSS / JavaScript / JQuery side of things, but we’ll see how it goes… &lt;/p&gt;  &lt;p&gt;I’ll try and post what I do to learn MVC and hopefully some other people in my situation can tag along &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/Windows-Live-Writer/MVC3The-Beginnings_12350/wlEmoticon-smile_2.png" /&gt;&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/147262.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/147262.aspx</wfw:comment>
        <slash:comments>1</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/147262.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/147262.aspx</trackback:ping>
    </entry>
    <entry>
        <title>MousePath</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/05/10/mousepath.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/05/10/mousepath.aspx</id>
        <published>2011-05-10T21:39:22-12:00:00</published>
        <updated>2011-05-10T21:39:22Z</updated>
        <content type="html">&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Logo_2.png" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; margin: 0px 30px 30px 0px; display: inline; border-top: 0px; border-right: 0px" title="Logo" border="0" alt="Logo" align="left" src="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Logo_thumb.png" width="220" height="101" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;A while ago, (and by that I mean over a year ago now) I was catching up on the blogs I read and came across this post:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://blog.iso50.com/14644/mousepaths-hiroyuki-hamada/" href="http://blog.iso50.com/14644/mousepaths-hiroyuki-hamada/"&gt;http://blog.iso50.com/14644/mousepaths-hiroyuki-hamada/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;I thought – &lt;strong&gt;Awesomeness! I’ll give that a go&lt;/strong&gt;… downloaded the app, and ran it, all good – but only on one monitor… :( I work with two monitors, and found that a lot of the time I’d end up with a no lines as I was on the other monitor…&lt;/p&gt;  &lt;p&gt;So, I thought I’d give it a go and write one myself… I actually had a working version pretty quickly, but when I say working, what I mean is one of the most impressive memory hogs and (indeed) cpu hogs I’ve written… &lt;/p&gt;  &lt;p&gt;Gradually improvements have come along, the cpu / memory issues are much &lt;em&gt;much&lt;/em&gt; better due to suggestions from a few people over the time I’ve mentioned it, and there are still shed loads more improvements to come along, the list would be pretty epic.&lt;/p&gt;  &lt;p&gt;So – why upload it now? Why not do those fixes and then publish it?&lt;/p&gt;  &lt;p&gt;Basically – I will continually tweak bits here and there, and it’ll never be done so no-one else would be able to fix it :)&lt;/p&gt;  &lt;p&gt;So here it is, it tracks your mouse, when you pause, and not a lot else, it works on 2 monitors, and should be fine on 1 or more! It generates a picture like this:&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Separate_2.png" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="Separate" border="0" alt="Separate" src="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Separate_thumb.png" width="644" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Which you can then combine with a PrtScn of your desktop, to get:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Combined_2.png" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="Combined" border="0" alt="Combined" src="http://geekswithblogs.net/images/geekswithblogs_net/cskardon/WindowsLiveWriter/MousePath_8DF1/Combined_thumb.png" width="644" height="260" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Anyhews, it’s at &lt;a href="http://mousepath.codeplex.com/"&gt;http://mousepath.&lt;a href="http://www.codeplex.com/" target="_blank"&gt;codeplex&lt;/a&gt;.com/&lt;/a&gt; feel free to play with it etc, (there’s no build at present, so it’s source-code-build for now)…&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Me…&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/145267.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/145267.aspx</wfw:comment>
        <slash:comments>0</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/145267.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/145267.aspx</trackback:ping>
    </entry>
    <entry>
        <title>It&amp;rsquo;s ok to throw System.Exception&amp;hellip;</title>
        <link rel="self" type="text/html" href="http://geekswithblogs.net/cskardon/archive/2011/02/23/itrsquos-ok-to-throw-system.exceptionhellip.aspx" />
        <id>http://geekswithblogs.net/cskardon/archive/2011/02/23/itrsquos-ok-to-throw-system.exceptionhellip.aspx</id>
        <published>2011-02-23T20:44:05-12:00:00</published>
        <updated>2011-02-23T20:44:05Z</updated>
        <content type="html">&lt;h2&gt;No. No it’s not.&lt;/h2&gt;  &lt;p&gt;It’s not just me saying that, it’s the Microsoft &lt;em&gt;guidelines&lt;/em&gt;: &lt;a href="http://msdn.microsoft.com/en-us/library/ms229007.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms229007.aspx&lt;/a&gt; &lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Do not &lt;strong&gt;throw&lt;/strong&gt; &lt;a href="http://msdn.microsoft.com/en-us/library/system.exception.aspx" target="_blank"&gt;System.Exception&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/system.systemexception.aspx" target="_blank"&gt;System.SystemException&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Also – as important:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Do not &lt;strong&gt;catch&lt;/strong&gt; System.Exception or System.SystemException in framework code, unless you intend to re-throw..&lt;/p&gt; &lt;/blockquote&gt;  &lt;h4&gt;Throwing:&lt;/h4&gt;  &lt;p&gt;Always, &lt;strong&gt;always&lt;/strong&gt; try to pick the most specific exception type you can, if the parameter you have received in your method is null, throw an &lt;a href="http://msdn.microsoft.com/en-us/library/system.argumentnullexception.aspx" target="_blank"&gt;ArgumentNullException&lt;/a&gt;, value received greater than expected? &lt;a href="http://msdn.microsoft.com/en-us/library/system.ArgumentOutOfRangeException.aspx" target="_blank"&gt;ArgumentOutOfRangeException&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;For example:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ArgChecker(&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt, &lt;span class="kwrd"&gt;string&lt;/span&gt; theString)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (theInt &amp;lt; 0)
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentOutOfRangeException(&lt;span class="str"&gt;"theInt"&lt;/span&gt;, theInt, &lt;span class="str"&gt;"theInt needs to be greater than zero."&lt;/span&gt;);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (theString == &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentNullException(&lt;span class="str"&gt;"theString"&lt;/span&gt;);

    &lt;span class="kwrd"&gt;if&lt;/span&gt; (theString.Length == 0)
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException(&lt;span class="str"&gt;"theString needs to have content."&lt;/span&gt;, &lt;span class="str"&gt;"theString"&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Why do we want to do this? It’s a lot of extra code when compared with a simple:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ArgChecker(&lt;span class="kwrd"&gt;int&lt;/span&gt; theInt, &lt;span class="kwrd"&gt;string&lt;/span&gt; theString)
{
    &lt;span class="kwrd"&gt;if&lt;/span&gt; (theInt &amp;lt; 0 || &lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrWhiteSpace(theString))
        &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Exception(&lt;span class="str"&gt;"The parameters were invalid."&lt;/span&gt;);
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;It all comes down to a couple of things; the catching of the exceptions, and the information you are passing back to the calling code. &lt;/p&gt;

&lt;h4&gt;Catching:&lt;/h4&gt;

&lt;p&gt;Ok, so let’s go with introduction level Exception handling, taught by many-a-university: You do all your work in a try clause, and catch anything wrong in the catch clause. So this tends to give us code like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt; {
   &lt;span class="rem"&gt;/* All the shizzle */&lt;/span&gt;
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt; {
   &lt;span class="rem"&gt;/* Deal with errors */&lt;/span&gt;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;But of course, we can improve on that by catching the exception so we can report on it:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt; { }
&lt;span class="kwrd"&gt;catch&lt;/span&gt;(Exception ex) { &lt;span class="rem"&gt;/* Log that 'ex' occurred? */&lt;/span&gt; }&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Now we’re at the point where people tend to go:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Brilliant, I’ve got exception handling nailed, what next???&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and code gets littered with the &lt;strong&gt;catch(Exception ex)&lt;/strong&gt; nastiness. Why is it nasty? Let’s imagine for a moment our code is throwing an &lt;em&gt;ArgumentNullException&lt;/em&gt; which we’re catching in the catch block and logging. Ok, the log entry has been made, so we can debug the code right? We’ve got all the info… What about an &lt;a href="http://msdn.microsoft.com/en-us/library/system.outofmemoryexception.aspx" target="_blank"&gt;OutOfMemoryException&lt;/a&gt; – what can we do with that?&lt;/p&gt;

&lt;p&gt;That’s right, not a lot, chances are you can’t even log it (you are out of memory after all), but you’ve caught it – and as such - have hidden it.&lt;/p&gt;

&lt;p&gt;So, as part of this, there are two things you can do one, is the rethrow method:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt; { &lt;span class="rem"&gt;/* code */&lt;/span&gt; }
&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
{
    &lt;span class="rem"&gt;//Log&lt;/span&gt;
    &lt;span class="kwrd"&gt;throw&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Note, it’s &lt;strong&gt;not&lt;/strong&gt; &lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;catch&lt;/span&gt; (Exception ex)
{
    &lt;strong&gt;&lt;span class="kwrd"&gt;throw&lt;/span&gt; ex;&lt;/strong&gt;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;as that will wipe all your important stack trace information. This does get your exception to continue, and is the &lt;strong&gt;only&lt;/strong&gt; reason you would catch Exception (anywhere other than a global catch-all) in your code. The other preferred method is to catch the exceptions you can deal with. &lt;/p&gt;

&lt;p&gt;It may not matter that the string I’m passing in is null, and I can cope with it like this:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;{
    DoSomething(myString);
}
&lt;span class="kwrd"&gt;catch&lt;/span&gt;(ArgumentNullException){}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;And that’s fine, it means that any exceptions I can’t deal with (OutOfMemory for example) will be propagated out to other code that &lt;em&gt;can&lt;/em&gt; deal with it. Of course, this is horribly messy, no one wants try / catch blocks &lt;em&gt;everywhere&lt;/em&gt; and that’s why Microsoft added the ‘Try’ methods to the framework, and it’s a strategy we &lt;em&gt;should&lt;/em&gt; continue. 

&lt;p&gt;If I try:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; i = (&lt;span class="kwrd"&gt;int&lt;/span&gt;) &lt;span class="str"&gt;"one"&lt;/span&gt;;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;I will get an &lt;a href="http://msdn.microsoft.com/en-us/library/system.InvalidCastException.aspx" target="_blank"&gt;InvalidCastException&lt;/a&gt; which means I need the try / catch block, but I could mitigate this using the ‘TryParse’ method:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;int&lt;/span&gt; i;
&lt;span class="kwrd"&gt;if&lt;/span&gt;(!Int32.TryParse(&lt;span class="str"&gt;"one"&lt;/span&gt;, &lt;span class="kwrd"&gt;out&lt;/span&gt; i))
   &lt;span class="kwrd"&gt;return&lt;/span&gt;;&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;style type="text/css"&gt;&lt;![CDATA[

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }]]&gt;&lt;/style&gt;

&lt;p&gt;Similarly, in the ‘DoSomething’ example, it might be beneficial to have a ‘TryDoSomething’ that returns a boolean value indicating the success of continuing. Obviously this isn’t practical in every case, so use the ol’ common sense approach.&lt;/p&gt;

&lt;p&gt;Onwards&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p align="left"&gt;Yer thanks Chris, I’m looking forward to writing tonnes of new code.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Fear not, that is where helpers come into it… (but that’s the next post)&lt;/p&gt;&lt;img src="http://geekswithblogs.net/cskardon/aggbug/144095.aspx" width="1" height="1" /&gt;</content>
        <wfw:comment>http://geekswithblogs.net/cskardon/comments/144095.aspx</wfw:comment>
        <slash:comments>2</slash:comments>
        <wfw:commentRss>http://geekswithblogs.net/cskardon/comments/commentRss/144095.aspx</wfw:commentRss>
        <trackback:ping>http://geekswithblogs.net/cskardon/services/trackbacks/144095.aspx</trackback:ping>
    </entry>
</feed>
