<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Many Hats of Jason Specland &#187; geek</title>
	<atom:link href="http://www.jasonspecland.com/tag/geek/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jasonspecland.com</link>
	<description>The mostly self-deprecating story of a programmer, performer, and daddy.</description>
	<lastBuildDate>Mon, 06 Feb 2012 17:51:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Sharepoint: Updating Workflow Task Causes NullReferenceException (a fix)</title>
		<link>http://www.jasonspecland.com/2011/07/11/sharepoint-updating-workflow-task-causes-nullreferenceexception-a-fix/</link>
		<comments>http://www.jasonspecland.com/2011/07/11/sharepoint-updating-workflow-task-causes-nullreferenceexception-a-fix/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 20:03:24 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[sharepoint]]></category>

		<guid isPermaLink="false">http://www.jasonspecland.com/?p=312</guid>
		<description><![CDATA[Hi there, ordinary blog readers! Unless you&#8217;re a SharePoint developer, this entry isn&#8217;t for you. I&#8217;m putting this up to save future developers the head-against-wall-banging that I encountered while trying to fix this problem. So, I&#8217;m kind of new to &#8230; <a href="http://www.jasonspecland.com/2011/07/11/sharepoint-updating-workflow-task-causes-nullreferenceexception-a-fix/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hi there, ordinary blog readers!  Unless you&#8217;re a SharePoint developer, this entry isn&#8217;t for you.  I&#8217;m putting this up to save future developers the head-against-wall-banging that I encountered while trying to fix this problem.</p>
<p>So, I&#8217;m kind of new to SharePoint, so naturally, the first thing I should be doing is writing a crazy insane workflow, right?</p>
<p>I&#8217;ve got a workflow where a project manager approves a project (that&#8217;s one kind of task), or can send it out for technical review (another kind of task), or can request more information from the user (yet another task).  Each of these tasks have their own Content Type, and their own custom task edit form in ASP.NET.  (Because I hate InfoPath with a burning white hot hate.)</p>
<p>Whenever someone uses one of these custom edit forms, however, I get a NullReferenceException.  The stack trace always puts it in the non-public SPListItem.PrepeareItemForUpdate method.  It doesn&#8217;t matter how I change the task list item.  Using SPWorkflowTask.AlterTask, or just SPContext.Current.ListItem followed by Update all threw the NullReferenceException.</p>
<p>To Google I go!  However, most of the results said that it had to do with not having a &lt;FieldRefs&gt; definition in the Content Types.  That wasn&#8217;t my problem, however, since not only did my Content Types have FieldRef&#8217;s, but they were very much full.</p>
<p>At my wits end, I broke out the .NET Reflector and decompiled the Microsoft.SharePoint assembly.  Here&#8217;s what I found:</p>
<p><a href="http://www.jasonspecland.com/wp-content/uploads/2011/07/splistitem.png"><img src="http://www.jasonspecland.com/wp-content/uploads/2011/07/splistitem.png" alt="" title="Screenshot of Decompilation of SPListItem.cs in Microsoft.SharePoint Assembly" width="1098" height="128" class="alignnone size-full wp-image-313" /></a></p>
<p>As you can see (well, kind of see&#8230; click on it to see more clearly), this would only happen in a WorkflowTask.  If the list item&#8217;s &#8220;Completed&#8221; field is null, the cast to bool throws a NullReferenceException.  This is probably the kind of thing that can&#8217;t happen in SharePoint Designer, but only would occur when someone is mucking about in Visual Studio.</p>
<p>To fix it, make sure you set the &#8220;Completed&#8221; field.  I do this:</p>
<pre class="brush: c#; ">

private void SetTaskStatus(string status, bool taskIsComplete) {
      SPListItem taskItem = SPContext.Current.ListItem;

      Hashtable taskData = new Hashtable();
      taskData[SPBuiltInFieldId.TaskStatus] = status;
      taskData[SPBuiltInFieldId.Completed] = taskIsComplete;
      if (taskIsComplete) {
        taskData[SPBuiltInFieldId.PercentComplete] = 1;
      }

      SPWorkflowTask.AlterTask(taskItem, taskData, true);
    }
</pre>
<p>Or, if you work for Microsoft, you could do us a favor and make sure that you null check that line and default to false.  (It&#8217;s entirely possible that this has been fixed by SP1, but my production server doesn&#8217;t run that yet, so I can&#8217;t either.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonspecland.com/2011/07/11/sharepoint-updating-workflow-task-causes-nullreferenceexception-a-fix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit Testing: Rhino Mocks, Ordered Mocks, and Events</title>
		<link>http://www.jasonspecland.com/2010/09/16/unit-testing-rhino-mocks-ordered-mocks-and-events/</link>
		<comments>http://www.jasonspecland.com/2010/09/16/unit-testing-rhino-mocks-ordered-mocks-and-events/#comments</comments>
		<pubDate>Thu, 16 Sep 2010 16:23:11 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[rhino mocks]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.jasonspecland.com/?p=188</guid>
		<description><![CDATA[Tired of all that improv show talk? Well, now it&#8217;s time for me to get my geek on. Non-computer geeks feel free to tune out. This is actually more along the lines of &#8220;put it out there for the sake &#8230; <a href="http://www.jasonspecland.com/2010/09/16/unit-testing-rhino-mocks-ordered-mocks-and-events/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Tired of all that improv show talk?  Well, now it&#8217;s time for me to get my geek on.  Non-computer geeks feel free to tune out.  This is actually more along the lines of &#8220;put it out there for the sake of future Googlers&#8221; than a serious discussion.</p>
<p>I&#8217;ve had test-first religion for some time now, but deadlines have made me something of a lapsed tester.  After finding a pretty bad-ass bug in my code, I got religion again, admitted I was a sinner, and went forward in Testing.  I am redeeming myself by writing a few hundred unit tests of already existing code.</p>
<p>My preferred mock framework is Rhino Mocks.  Now I&#8217;m all about the AAA (Arrange, Act, Assert) syntax.  99.9% of my tests (seriously, I&#8217;ve got over a thousand of them) are AAA.  Most of my tests are unordered.  I just want to test that something was called, and I don&#8217;t care what was called before or after it.</p>
<p>But you can&#8217;t do AAA syntax when you&#8217;re doing ordered tests.  It hasn&#8217;t been a problem thus far, but I ran into a problem when I started testing objects that hooked up events in the constructor: So my code looked like this:</p>
<pre class="brush: c#; ">

namespace RhinoMocksOrdredWithEvents {
    public interface IOrderedThing {
        void FirstThing();
        void SecondThing();
        void SomethingElse();
        event EventHandler&lt;EventArgs&gt; OnThingHappened;
    }

    public class MyTestClass {

        private IOrderedThing MyOrderedThing { get; set; }

        public MyTestClass(IOrderedThing orderedThing) {
            MyOrderedThing = orderedThing;
            MyOrderedThing.OnThingHappened += new EventHandler&lt;EventArgs&gt;(MyOrderedThing_OnThingHappened);
            MyOrderedThing.SomethingElse();
        }

        public void DoThingsInOrder() {

            MyOrderedThing.SomethingElse();

            MyOrderedThing.FirstThing();
            MyOrderedThing.SecondThing();
        }

        private void MyOrderedThing_OnThingHappened(object sender, EventArgs e) {
            return;
        }

    }
}
</pre>
<p>And here&#8217;s the test to make sure that FirstThing() and SecondThing() are called in order:</p>
<pre class="brush: c#; ">

namespace RhinoMocksOrdredWithEvents {
    [TestClass]
    public class OrderedMockTests { 

        [TestMethod]
        public void TestThingsAreRunInOrder() {
            // Arrange
            MockRepository mocks = new MockRepository(); 

            IOrderedThing mockOrderedThing = mocks.DynamicMock&lt;IOrderedThing&gt;(); 

            MyTestClass classUnderTest = new MyTestClass(mockOrderedThing); 

            using (mocks.Record()) {
                using (mocks.Ordered()) {
                    mockOrderedThing.Expect(thing =&gt; thing.FirstThing());
                    mockOrderedThing.Expect(thing =&gt; thing.SecondThing());
                }
            } 

            mockOrderedThing.Replay(); 

            // Act
            classUnderTest.DoThingsInOrder(); 

            // Assert
            mockOrderedThing.VerifyAllExpectations();
        }
    }
} 
</pre>
<p>Be not fooled by my spurious use of the //Arange, //Act, and //Assert comments.  This is most definitely not the AAA syntax.</p>
<p>So when I tried to run this test, I got the following error:</p>
<p><code><br />
Test method<br />
RhinoMocksOrdredWithEvents.OrderedMockTests.TestThingsAreRunInOrder<br />
threw exception:<br />
Rhino.Mocks.Exceptions.ExpectationViolationException:<br />
IOrderedThing.add_OnThingHappened(System.EventHandler`1[System.EventArgs]);<br />
Expected #1, Actual #0..<br />
</code></p>
<p>What what what!?  I never told Rhino Mocks that I expected the event to be wired!  And anyway, it <i>is</i> wired, right there in the constructor, see?  Then I comment out the event hookup, and the test works!  So off I sauntered to the Rhino Mocks mailing list all like, &#8220;Hey guys, I don&#8217;t mean to be all smug and stuff, but all y&#8217;all got a bug.&#8221;</p>
<p>Thankfully, <a href="http://devlicio.us/blogs/tim_barcz/">Tim Barcz</a> on the mailing list set me straight.</p>
<p>Yes, Virginia, you <i>can</i> do the AAA syntax in an ordered mock, and this is how you do it:</p>
<pre class="brush: c#; ">

namespace RhinoMocksOrdredWithEvents {
    [TestClass]
    public class OrderedMockTests {

        [TestMethod]
        public void TestThingsAreRunInOrder() {
            // Arrange
            //MockRepository mocks = new MockRepository();

            IOrderedThing mockOrderedThing = MockRepository.GenerateMock&lt;IOrderedThing&gt;();

            MyTestClass classUnderTest = new MyTestClass(mockOrderedThing);

            mockOrderedThing.GetMockRepository().Ordered();

            mockOrderedThing.Expect(thing =&gt; thing.FirstThing());
            mockOrderedThing.Expect(thing =&gt; thing.SecondThing());

            // Act
            classUnderTest.DoThingsInOrder();

            // Assert
            mockOrderedThing.VerifyAllExpectations();

        }
    }
}
</pre>
<p>Which works no matter what strange stuff you want to do in the constructor.</p>
<p>Much thanks to Tim Barcz for setting me straight.  Here is <a href="http://groups.google.com/group/rhinomocks/browse_thread/thread/7bfe0b3e2fc59baf/2dbbdc920e78f10a#2dbbdc920e78f10a">the original thread on the Rhino Mocks mailing list</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonspecland.com/2010/09/16/unit-testing-rhino-mocks-ordered-mocks-and-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging WCF Services In Visual Studio 2008 in 32-bit Mode on a 64-bit Architecture</title>
		<link>http://www.jasonspecland.com/2010/06/15/debugging-wcf-services-in-visual-studio-2008-in-32-bit-mode-on-a-64-bit-architecture/</link>
		<comments>http://www.jasonspecland.com/2010/06/15/debugging-wcf-services-in-visual-studio-2008-in-32-bit-mode-on-a-64-bit-architecture/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 14:25:59 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://www.jasonspecland.com/?p=100</guid>
		<description><![CDATA[This is for my own reference, (and for the sake of anyone Googling) since this has been driving me crazy for months. Feel free to ignore if you&#8217;re not a geek. Feel free to correct it if you are. When &#8230; <a href="http://www.jasonspecland.com/2010/06/15/debugging-wcf-services-in-visual-studio-2008-in-32-bit-mode-on-a-64-bit-architecture/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>This is for my own reference, (and for the sake of anyone Googling) since this has been driving me crazy for months.  Feel free to ignore if you&#8217;re not a geek.  Feel free to correct it if you are.</p>
<p>When building a WCF project for the x86 architecture on an x64 machine/OS (like, say, Windows 7), you will get a BadFormatException when you try to debug it.  This is because WcfSvcHost.exe will run in the mode defined by your architecture, regardless of your particular build environment.  Microsoft says that this is working as intended.  I say boloney, but I&#8217;m a VS version behind now.  (I haven&#8217;t tested VS 2010 yet.)</p>
<p><a href="https://connect.microsoft.com/VisualStudio/feedback/details/349510/vs2008-incorrectly-launches-x64-version-of-wcfsvchost-for-x86-debugging?wa=wsignin1.0#">Here is a link to part of the solution.</a></p>
<p><code><br />
corflags /32BIT+ WcfSvcHost.exe<br />
</code></p>
<p>However, the signature of this assembly is now broken, and won&#8217;t load.  So to bypass that:</p>
<p><code><br />
sn -Vr WcfSvcHost.exe<br />
</code></p>
<p>to remove strong name signature verification.</p>
<p><b>DANGER:</b><br />
Don&#8217;t do that unless you know what you&#8217;re doing!  That opens up a <i>huge</i> security risk.  Do not do that in a production environment!  Only do it on your dev box!</p>
<p>Why not just build the app in x64 or (even better) Any CPU?  Because I can&#8217;t get Oracle.DataAccess in 64-bit.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonspecland.com/2010/06/15/debugging-wcf-services-in-visual-studio-2008-in-32-bit-mode-on-a-64-bit-architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Praxis: Goldbach&#8217;s Conjecture</title>
		<link>http://www.jasonspecland.com/2010/03/02/programming-praxis-goldbachs-conjecture/</link>
		<comments>http://www.jasonspecland.com/2010/03/02/programming-praxis-goldbachs-conjecture/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 03:26:26 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[praxis]]></category>

		<guid isPermaLink="false">http://www.jasonspecland.com/?p=72</guid>
		<description><![CDATA[Since I mentioned in my last post that I live in fear of the tech interview, I decided to do something about it rather than live in fear. To that end, I subscribed to a website called Programming Praxis, which &#8230; <a href="http://www.jasonspecland.com/2010/03/02/programming-praxis-goldbachs-conjecture/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since I mentioned in my last post that I live in fear of the tech interview, I decided to do something about it rather than live in fear.  To that end, I subscribed to a website called Programming Praxis, which publishes short programming problems to sharpen your saw on.  (Well, I&#8217;d actually been a subscriber for a while, but it&#8217;s just now that I&#8217;ve actually took the time to do my own saw sharpening.)</p>
<p>Geek Content Ahead.  Feel Free to Ignore.</p>
<p><a href="http://programmingpraxis.com/2010/03/02/goldbachs-conjecture/">Today&#8217;s Praxis</a> is on the <a href="http://en.wikipedia.org/wiki/Goldbach_conjecture">Goldbach Conjecture</a> which states that any even number greater than 2 can be expressed as the sum of two primes.  The challenge is to write a program that will take in an even number, and spit out the two primes that can be added together to make it.</p>
<p>I realize my solution is extremely naive, but it&#8217;s the first time in a long time that I&#8217;ve actually worked on programming problems other than &#8220;get data from database a, transform it somehow, and put it in database b.&#8221;  Also, for extra difficulty (and speed, although my algorithm is the real speed hangup in this case) I wrote it in C.</p>
<p>For the one or two people still reading, here is my extremely naive solution, cobbled together while watching West Side Story on TCM.</p>
<pre class="brush: cpp; ">

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

void show_usage();
unsigned long *create_sieve_to_number(unsigned long number);

int main (int argc, const char * argv[]) {

    if (argc != 2) {
		show_usage();
		return -1;
	}

	unsigned long number = atol(argv[1]);

	if ((number % 2) != 0) {
		show_usage();
		return -1;
	}

	unsigned long *sieve = create_sieve_to_number(number);

	for (unsigned long i = 2; i &lt; number; i++) {
		if (sieve[i] == 1) {
			for (unsigned long j = i; j &lt; number; j++) {
				if (sieve[j] == 1) {
					if (i + j == number) {
						printf(&quot;Solution found: %d + %d\n&quot;, i, j);
						return 0;
					}
				}
			}
		}
	}

	printf(&quot;no solution found!  pick up your Fields Medal!\n&quot;);

	return 0;

}

void show_usage(void) {
	printf(&quot;usage: goldbach [even number]\n&quot;);
}

unsigned long *create_sieve_to_number(unsigned long number) {
	unsigned long *sieve;

	sieve = (unsigned long *)malloc(sizeof(unsigned long) * (number + 1));

	for (int i = 0; i &lt; number; i++) {
		sieve[i] = 1;
	}

	for (unsigned long i = 2; i &lt; number; i++) {
		if (sieve[i] == 1) {
			for (unsigned long j = i * i; j &lt; number; j = j + i) {
				sieve[j] = 0;
			}
		}
	}

	return sieve;
}
</pre>
<p><b>Edit:</b> See what happens when you&#8217;re watching TV when you&#8217;re doing your homework?  The flags marking numbers as prime can be a bool (or even a bit) and most certainly does <i>not</i> have to be an unsigned long.  Yay for massive, massive wastes of memory!  (But hey, I <i>was</i> watching West Side Story&#8230;)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonspecland.com/2010/03/02/programming-praxis-goldbachs-conjecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Dreaded Technology Test</title>
		<link>http://www.jasonspecland.com/2010/02/23/the-dreaded-technology-test/</link>
		<comments>http://www.jasonspecland.com/2010/02/23/the-dreaded-technology-test/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 17:14:14 +0000</pubDate>
		<dc:creator>jason</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[anxiety]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[interview]]></category>

		<guid isPermaLink="false">http://www.jasonspecland.com/?p=70</guid>
		<description><![CDATA[A recent post on Coding Horror about &#8220;Non-Programmer Programmers&#8221; kind of terrified me. Not because I think that my job is going away, and not because I think my skills aren&#8217;t up to snuff, but because the technical interview terrifies &#8230; <a href="http://www.jasonspecland.com/2010/02/23/the-dreaded-technology-test/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A recent <a href="http://www.codinghorror.com/blog/2010/02/the-nonprogramming-programmer.html">post on Coding Horror</a> about &#8220;Non-Programmer Programmers&#8221; kind of terrified me.  Not because I think that my job is going away, and not because I think my skills aren&#8217;t up to snuff, but because the technical interview terrifies me like nothing else.</p>
<p>Jason, with performance anxiety?  Yes, it&#8217;s true!</p>
<p>As a performer, I come from the world of improv, where the mantra is &#8220;Just make it up!  What you say will always be correct!&#8221;  Naturally, this level of bullshittery, while it <i>might</i> get you through a real interview, will never do in a technical interview where you will be eviscerated if you don&#8217;t know the systems you claim to know.  (Or even some detail of a system you really do know, but had never previously used.)  Now I&#8217;ve never put something on my résumé that I did not actually use, but in some cases, it&#8217;s just been a while and I need a few minutes with my friend Google to get back up to speed.</p>
<p>Part of the problem is that the tech interview is like flying an airplane.  Once you stall once, it&#8217;s really hard not to crash and burn.  You just get more and more flustered until you can&#8217;t even answer questions about things that you <i>do</i> know extensively.</p>
<p>I had an interview like that just before I interviewed for my current job.  It was October/November 2001, and as you could imagine, New York City was on edge and not in a hiring mood, especially in the &#8220;dot-com&#8221; world which had gone bust.  I interviewed downtown with a famous phone company for a unix administrator job.  I can&#8217;t remember what question started the stall&#8230; I think it was something about rpc, or what port something listened on&#8230; But after that, I was dead in the water.  They asked me a bog-simple RAID question that I totally blew.  As they escorted me out of the building, one of the managers sypathetically said to me, &#8220;It must be hard getting a job in this economy&#8230;&#8221;  Shellshocked, I agreed.</p>
<p>Reading that article on Coding Horror, and remembering that interview, kept me awake far too late last night.  Again, I&#8217;m reasonably confident that my job&#8217;s not going anywhere, and I&#8217;m confident in my abilities, but one has to plan for these things.</p>
<p>Then today, sitting in the office that I&#8217;ve occupied for almost nine years now, I remembered a tech interview that was tough, but I knocked out of the park.  (In particular, I remember totally killing a question about DNS.)  Naturally, its the one that got me the job I have today.  And they seem to like me after all these years, to the point where they actually let me write production code.</p>
<p>Scary though the tech interview may be, if I keep my skills up, keep my cool, and remember how to pull out of a stall, I should be okay.  Besides, the &#8220;weed out&#8221; questions on that Coding Horror article are laughably easy.  And if your tech interview feels like the Spanish Inquisition, did I really want to work for you in the first place?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jasonspecland.com/2010/02/23/the-dreaded-technology-test/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

