<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" 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:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Rory Primrose</title>
    <description>I don't have a solution but I admire the problem</description>
    <link>http://neovolve.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.5.0.7</generator>
    <language>en-AU</language>
    <blogChannel:blogRoll>http://neovolve.com/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.neovolve.com/syndication.axd</blogChannel:blink>
    <dc:creator>Rory Primrose</dc:creator>
    <dc:title>Rory Primrose</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/RoryPrimrose" type="application/rss+xml" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
      <title>Using testrunconfig sometimes fails to deploy dependencies</title>
      <description>&lt;p&gt;I&amp;rsquo;ve never been a fan of deploying test dependencies using testrunconfig. I prefer dependencies to be located as closely as possible to where they are used, ideally on an individual unit test. Using testrunconfig means that the dependencies are deploy at the solution level.&lt;/p&gt;
&lt;p&gt;Having dependencies attached to each unit test for my current project has become unmaintainable however as almost all unit tests require the same dependencies. This makes testrunconfig appropriate in this case.&lt;/p&gt;
&lt;p&gt;The issue I found with deploying dependencies with testrunconfig is that the dependency is not deployed into the TestResults directory when a new dependency reference is added to the config. This appears to be a bug in &lt;a href="http://msdn.microsoft.com/vstudio" target="_blank"&gt;Visual Studio&lt;/a&gt; where the testrunconfig contents is cached. The workaround is to reload the solution. Each time this happens I have actually closed the IDE and opened the solution again. When the test run is executed the dependencies are not deployed as expected.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/i8oYTHfi768" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/i8oYTHfi768/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/10/23/Using-testrunconfig-sometimes-fails-to-deploy-dependencies.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=10f910b0-d1bf-4141-871f-012f70874e65</guid>
      <pubDate>Fri, 23 Oct 2009 11:45:00 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=10f910b0-d1bf-4141-871f-012f70874e65</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=10f910b0-d1bf-4141-871f-012f70874e65</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/10/23/Using-testrunconfig-sometimes-fails-to-deploy-dependencies.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=10f910b0-d1bf-4141-871f-012f70874e65</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=10f910b0-d1bf-4141-871f-012f70874e65</feedburner:origLink></item>
    <item>
      <title>Changing a TFS bound solution namespace</title>
      <description>&lt;p&gt;Changing the namespace of a solution that has already progressed significantly down the development path can be a pain. &lt;a href="http://msdn.microsoft.com/vstudio" target="_blank"&gt;Visual Studio&lt;/a&gt; doesn&amp;rsquo;t native support namespace refactoring and tools like &lt;a href="http://www.jetbrains.com/resharper" target="_blank"&gt;ReSharper&lt;/a&gt; can get bogged down with a huge set of changes. There is usually a dirty result if either of these tools are used as the project and solution directories are not renamed. These need to be done manually in Source Code Explorer which then throws out the relative paths stored in the solution file.&lt;/p&gt;
&lt;p&gt;Changing a namespace can be a messy job. In these circumstances it&amp;rsquo;s often best to hand craft an external solution to this problem. I&amp;rsquo;ve finally written that solution as a console app after doing this job the painful manual way too many times.&lt;/p&gt;
&lt;p&gt;The attached file contains the console application code. There is no defensive code against exceptions so it&amp;rsquo;s best to run this in the IDE. There are three constants you need to update before running this. These are the root path, find text and replace text. The code records everything that happens out to the console and a log file that is unique for each run.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://neovolve.com/file.axd?file=2009%2f10%2fProgram.cs"&gt;Program.cs (11.54 kb)&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/ZeWmshx5TT0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/ZeWmshx5TT0/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/10/06/Changing-a-TFS-bound-solution-namespace.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=56b996cb-5af9-4d67-ae79-2b09801ffcdf</guid>
      <pubDate>Tue, 06 Oct 2009 11:17:00 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=56b996cb-5af9-4d67-ae79-2b09801ffcdf</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=56b996cb-5af9-4d67-ae79-2b09801ffcdf</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/10/06/Changing-a-TFS-bound-solution-namespace.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=56b996cb-5af9-4d67-ae79-2b09801ffcdf</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=56b996cb-5af9-4d67-ae79-2b09801ffcdf</feedburner:origLink></item>
    <item>
      <title>ThreadStatic gotcha with ASP.Net</title>
      <description>&lt;p&gt;I had a requirement recently in a service implementation that business rules at any point throughout the execution of a service request could determine a message to return in the header of the response. Because these circumstances don’t affect the execution of the request (no exception is thrown), I needed a loosely coupled way of recording all the required messages and handling them higher up the stack.&lt;/p&gt;  &lt;p&gt;Storing data against the executing thread was the obvious solution. I considered manually storing information in the context data of the thread, but then thought this would be a great opportunity to use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.threadstaticattribute(VS.71).aspx" target="_blank"&gt;ThreadStaticAttribute&lt;/a&gt;. I coded this up and it all seemed to work well.&lt;/p&gt;  &lt;p&gt;Yesterday a bug was raised against this code because messages unrelated to the service request were being returned. I looked at the code and rechecked the ThreadStatic documentation. It shouldn’t be possible, but it was definitely happening. &lt;/p&gt;  &lt;p&gt;I quickly realised that the thread must be being reused across multiple service requests. This reminded me that ASP.Net uses a ThreadPool and it would not be doing any clean up of ThreadStatic data as it reused an existing thread for a new service request. &lt;/p&gt;  &lt;p&gt;The simple fix was to reset the ThreadStatic reference when the response is generated.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/jZghBM-73yA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/jZghBM-73yA/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/09/23/ThreadStatic-gotcha-with-ASPNet.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=f99ae6dd-6843-4987-81f5-e39798b9f967</guid>
      <pubDate>Wed, 23 Sep 2009 06:40:42 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=f99ae6dd-6843-4987-81f5-e39798b9f967</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=f99ae6dd-6843-4987-81f5-e39798b9f967</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/09/23/ThreadStatic-gotcha-with-ASPNet.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=f99ae6dd-6843-4987-81f5-e39798b9f967</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=f99ae6dd-6843-4987-81f5-e39798b9f967</feedburner:origLink></item>
    <item>
      <title>DisconnectedContext when debugging with MSTest</title>
      <description>&lt;p&gt;I have been hitting a DisconnectedContext issue when I’ve been running MSTest in the &lt;a href="http://msdn.microsoft.com/vstudio" target="_blank"&gt;Visual Studio&lt;/a&gt; IDE with the debugger attached. At first I thought it was an issue with debugging &lt;a href="http://wf.netfx3.com" target="_blank"&gt;WF&lt;/a&gt;, but it is now also happening with LINQ to SQL.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.neovolve.com/image.axd?picture=image_7.png" width="469" height="313" /&gt; &lt;/p&gt;  &lt;p&gt;The debugging on the thread of the executing test appears to be stopped when this is hit. Other threads/tests in the test run will still hit breakpoints however.&lt;/p&gt;  &lt;p&gt;Searching the net hasn’t yielded any pointers. Anyone out there have some information about this?&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/2i6HifKKD6g" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/2i6HifKKD6g/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/09/18/DisconnectedContext-when-debugging-with-MSTest.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=25b9db83-8c04-49dd-a3f8-cc1ab2835974</guid>
      <pubDate>Fri, 18 Sep 2009 10:42:46 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=25b9db83-8c04-49dd-a3f8-cc1ab2835974</pingback:target>
      <slash:comments>3</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=25b9db83-8c04-49dd-a3f8-cc1ab2835974</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/09/18/DisconnectedContext-when-debugging-with-MSTest.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=25b9db83-8c04-49dd-a3f8-cc1ab2835974</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=25b9db83-8c04-49dd-a3f8-cc1ab2835974</feedburner:origLink></item>
    <item>
      <title>Adding delete comment support to the Commentor extension</title>
      <description>&lt;p&gt;The &lt;a href="http://rtur.net/blog/post/2009/02/16/Commentor-e28093-new-version.aspx" target="_blank"&gt;Commentor&lt;/a&gt; extension for &lt;a href='http://www.dotnetblogengine.net' target='_blank'&gt;BlogEngine.Net&lt;/a&gt; written by &lt;a href="http://rtur.net/blog/" target="_blank"&gt;rtur&lt;/a&gt; is a great extension for catching comment spam on the blog. Unfortunately the custom rules you can apply to comments only support a Block or Allow action. &lt;/p&gt;  &lt;p&gt;What I want is to prevent the comments being saved at all if a manual rule has been violated. This is better for my needs as I don’t need to clean up the comments on the blog and I don’t get hassled by constant emails regarding comments that require moderation.&lt;/p&gt;  &lt;p&gt;The changes to the extension to support this are relatively minor.&lt;/p&gt;  &lt;p&gt;First is a change to the User controls\Commentor\Settings.aspx user control. The action dropdown now has a Delete action.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f9b7652b-855b-4f13-8b21-941a51c992bf" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="xml"&gt;&amp;lt;td&amp;gt;
    &amp;lt;asp:DropDownList ID="ddAction" runat="server"&amp;gt;
        &amp;lt;asp:ListItem Text="Block" Value="Block" Selected=true&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
        &amp;lt;asp:ListItem Text="Allow" Value="Allow" Selected=false&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
        &amp;lt;asp:ListItem Text="Delete" Value="Delete" Selected=false&amp;gt;&amp;lt;/asp:ListItem&amp;gt;
    &amp;lt;/asp:DropDownList&amp;gt;
&amp;lt;/td&amp;gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The next set of changes were to implement the Delete action in the App_Code\Extensions\Commentor.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt; class.&lt;/p&gt;

&lt;p&gt;The ManualFilter enum definition has been extended to include the Delete action.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d32bedae-813b-432a-bcfd-d55b2d9cd482" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;private enum ManualFilter { None, Block, Allow }&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The Post_AddingComment method now supports this enum value in its processing of a new comment.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:bc37574c-0a13-4835-bef7-7df1f4f25638" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;// validate against filter
switch (CheckFilter(comment))
{
    case ManualFilter.Block:
        comment.IsApproved = false;
        return;
    case ManualFilter.Allow:
        comment.IsApproved = true;
        return;
    case ManualFilter.Delete:
        comment.IsApproved = false;
        e.Cancel = true;
        return;
    default:
        break;
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;And finally, the CheckRow method has been updated to use the new Delete action.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:d66aa774-b4c8-457c-abae-6dbebb0cd80e" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;if (match)
{
    if (action == "Block")
        return ManualFilter.Block;
    if (action == "Delete")
        return ManualFilter.Delete;
    return ManualFilter.Allow;
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Make these changes and you will be able to use delete actions to prevent comments from being saved. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The settings for existing rules will need to be updated where they are stored (most likely in a database or xml file) in order for them to use the Delete action. A restart of the website will be required to pick up these changes that were made directly against the settings datastore. Alternatively you will need to delete and recreate any existing custom rules that you want to use the Delete action with.&lt;/p&gt;

&lt;p&gt;My Commentor extension settings now look like the following.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Commentor settings" border="0" alt="Commentor settings" src="http://www.neovolve.com/image.axd?picture=image_4.png" width="433" height="541" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/WYPMH9FY2y0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/WYPMH9FY2y0/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/09/15/Adding-delete-comment-support-to-the-Commentor-extension.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=5a5fed2e-7a6c-4f3e-873b-48e9814231a2</guid>
      <pubDate>Tue, 15 Sep 2009 09:24:52 +0600</pubDate>
      <category>Applications</category>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=5a5fed2e-7a6c-4f3e-873b-48e9814231a2</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=5a5fed2e-7a6c-4f3e-873b-48e9814231a2</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/09/15/Adding-delete-comment-support-to-the-Commentor-extension.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=5a5fed2e-7a6c-4f3e-873b-48e9814231a2</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=5a5fed2e-7a6c-4f3e-873b-48e9814231a2</feedburner:origLink></item>
    <item>
      <title>Sense of satisfaction</title>
      <description>&lt;p&gt;I just found out that something I came up with a few years ago in another job has hit production and is making a big difference. There were a lot of people involved in supporting the idea and some innovators who took the concept and applied it in ways I didn’t think of. Overall it is a great result and I’m very happy to see such a change being applied.&lt;/p&gt;  &lt;p&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="seal" border="0" alt="seal" src="http://www.neovolve.com/image.axd?picture=seal.gif" width="350" height="350" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/7QvylCFAHE4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/7QvylCFAHE4/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/09/15/Sense-of-satisfaction.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=2e18204c-4c55-495d-9a30-855c569d3325</guid>
      <pubDate>Tue, 15 Sep 2009 04:46:24 +0600</pubDate>
      <category>Personal</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=2e18204c-4c55-495d-9a30-855c569d3325</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=2e18204c-4c55-495d-9a30-855c569d3325</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/09/15/Sense-of-satisfaction.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=2e18204c-4c55-495d-9a30-855c569d3325</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=2e18204c-4c55-495d-9a30-855c569d3325</feedburner:origLink></item>
    <item>
      <title>Quick tip for undoing unchanged TFS checkouts</title>
      <description>&lt;p&gt;Reviewing changesets with a large number of files that haven’t changed can be a significant waste of time. Sliming changesets down to only changed files is a great idea before checking in files. &lt;/p&gt;  &lt;p&gt;I have previously been doing this manually which in itself is time consuming. Fortunately the &lt;a href="http://msdn2.microsoft.com/en-us/teamsystem/aa718825.aspx" target="_blank"&gt;TFS&lt;/a&gt; power toys package comes with a handy utility to automatically uncheck out any files that haven’t changed. Running TFPT.exe uu /r will do the trick. Running up an instance of the &lt;a href="http://msdn.microsoft.com/vstudio" target="_blank"&gt;Visual Studio&lt;/a&gt; command prompt and entering in this command can also be a hassle. Thankfully &lt;a href="http://msdn.microsoft.com/vstudio" target="_blank"&gt;Visual Studio&lt;/a&gt; makes this easy with the support for external tools.&lt;/p&gt;  &lt;p&gt;To set this up, go to Tools –&amp;gt; External Tools which will display the following dialog:&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="External Tools" border="0" alt="External Tools" src="http://www.neovolve.com/image.axd?picture=image_3.png" width="475" height="464" /&gt; &lt;/p&gt;  &lt;p&gt;Click Add and enter the following settings (full Command value is C:\Program Files\&lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt; Team Foundation Server 2008 Power Tools\TFPT.exe)&lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.neovolve.com/image.axd?picture=image_6.png" width="475" height="464" /&gt; &lt;/p&gt;  &lt;p&gt;Sending the output to the Output Window makes this setup really easy to review the changes.&lt;/p&gt;  &lt;p&gt;The Tools menu should now contain the Undo Null Changes command.&lt;/p&gt;  &lt;p&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.neovolve.com/image.axd?picture=image_5.png" width="300" height="156" /&gt; &lt;/p&gt;  &lt;p&gt;Enjoy.&lt;/p&gt;  &lt;p&gt;Update: Set initial directory to $(SolutionDir) as sometimes the workspace can’t be determined depending on the context of how the command is launched.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/-qtDYqwbVHY" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/-qtDYqwbVHY/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/09/09/Quick-tip-for-undoing-unchanged-TFS-checkouts.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=3be49161-642d-473c-8d5d-a8297e98e388</guid>
      <pubDate>Wed, 09 Sep 2009 05:13:26 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=3be49161-642d-473c-8d5d-a8297e98e388</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=3be49161-642d-473c-8d5d-a8297e98e388</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/09/09/Quick-tip-for-undoing-unchanged-TFS-checkouts.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=3be49161-642d-473c-8d5d-a8297e98e388</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=3be49161-642d-473c-8d5d-a8297e98e388</feedburner:origLink></item>
    <item>
      <title>Custom fields support with SqlMetadataStore in the sync framework</title>
      <description>&lt;p&gt;I am putting together a sync framework provider and have come across some issues that do not appear to be documented. I’m adding custom fields to the item metadata so that I can store additional information for items that are synchronised with another provider. To do this, you define the custom fields for items as part of initializing the metadata store. The tricky thing is that it isn’t clear what data types are supported and how to correctly use the data types that are supported.&lt;/p&gt;  &lt;p&gt;I have the following initialization code.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f0ae741d-53b8-4220-aa13-3b36b2b73b97" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;List&amp;lt;FieldSchema&amp;gt; customFields = new List&amp;lt;FieldSchema&amp;gt;
                                     {
                                         new FieldSchema("IsContainer", typeof(Boolean)),
                                         new FieldSchema("Name", typeof(String)),
                                         new FieldSchema("Path", typeof(String))
                                     };
String[] indexFieldNames = new[]
                               {
                                   "IsContainer", "Name", "Path"
                               };
List&amp;lt;IndexSchema&amp;gt; indexFields = new List&amp;lt;IndexSchema&amp;gt;
                                    {
                                        new IndexSchema(indexFieldNames, true)
                                    };

Metadata = MetaStore.InitializeReplicaMetadata(IdFormats, ReplicaId, customFields, indexFields);&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This code throws the following exception:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;&lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Synchronization.MetadataStorage.MetadataStoreInvalidOperationException: Incorrect constructor used&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It turns out that defining a FieldSchema as a string requires a defined length, hence the incorrect constructor has been used as there is another constructor that takes the size in addition to the name and type used here. This is not a good exception message as it does not adequately describe why there is a problem or how to fix it. The remarks documentation for the name and type constructor overload is also incorrect as it says the following.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;This form of the constructor sets &lt;/em&gt;&lt;em&gt;MaxLength&lt;/em&gt;&lt;em&gt; to the size of dataType, in bytes.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There must be something wrong with the implementation of this constructor as this does not appear to be the case. If the length is provided to the constructor overload then no exception is thrown when constructing FieldSchema instances.&lt;/p&gt;

&lt;p&gt;The code now looks like the following:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:cea8e8bf-fad2-4305-a4bd-5b760514f2af" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;List&amp;lt;FieldSchema&amp;gt; customFields = new List&amp;lt;FieldSchema&amp;gt;
                                     {
                                         new FieldSchema("IsContainer", typeof(Boolean)),
                                         new FieldSchema("Name", typeof(String), 256),
                                         new FieldSchema("Path", typeof(String), 256)
                                     };
String[] indexFieldNames = new[]
                               {
                                   "IsContainer", "Name", "Path"
                               };
List&amp;lt;IndexSchema&amp;gt; indexFields = new List&amp;lt;IndexSchema&amp;gt;
                                    {
                                        new IndexSchema(indexFieldNames, true)
                                    };

Metadata = MetaStore.InitializeReplicaMetadata(IdFormats, ReplicaId, customFields, indexFields);&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This now throws an exception saying:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;System.NotSupportedException: The data type is not supported.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;With a stack trace that looks like the following:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;&lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Synchronization.MetadataStorage.Utility.ConvertDataTypeToSyncMetadataFieldType(Type dataType) 
      &lt;br /&gt;&lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Synchronization.MetadataStorage.SqlMetadataStore.CreateCustomFieldDefinition(FieldSchema fieldSchema, String parameterName) 

      &lt;br /&gt;&lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Synchronization.MetadataStorage.SqlMetadataStore.InitializeReplicaMetadata(SyncIdFormatGroup idFormats, SyncId replicaId, IEnumerable`1 customItemFieldSchemas, IEnumerable`1 customIndexedFieldSchemas) 

      &lt;br /&gt;Neovolve.Jabiru.Client.Synchronization.Remote.StoreSyncProvider.LoadMetadataStore() in R:\&lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt;\Jabiru\Jabiru\Neovolve.Jabiru.Client\Neovolve.Jabiru.Client.Synchronization.Remote\StoreSyncProvider.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt;: line 668 

      &lt;br /&gt;Neovolve.Jabiru.Client.Synchronization.Remote.StoreSyncProvider..ctor(IStoreProcessor processor) in R:\&lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt;\Jabiru\Jabiru\Neovolve.Jabiru.Client\Neovolve.Jabiru.Client.Synchronization.Remote\StoreSyncProvider.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt;: line 64 

      &lt;br /&gt;Neovolve.Jabiru.Client.Synchronization.Remote.UnitTests.ServiceSyncProviderTests.RunSync(String localPath, IStoreProcessor processor, Guid storeGuid) in R:\&lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt;\Jabiru\Jabiru\Neovolve.Jabiru.Client\Neovolve.Jabiru.Client.Synchronization.Remote.UnitTests\ServiceSyncProviderTests.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt;: line 160 

      &lt;br /&gt;Neovolve.Jabiru.Client.Synchronization.Remote.UnitTests.ServiceSyncProviderTests.SyncDeletesItemFromProcessorWhenFileIsDeletedTest() in R:\&lt;a href="http://www.codeplex.com" target="_blank"&gt;CodePlex&lt;/a&gt;\Jabiru\Jabiru\Neovolve.Jabiru.Client\Neovolve.Jabiru.Client.Synchronization.Remote.UnitTests\ServiceSyncProviderTests.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt;: line 116&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you follow down the rabbit hole using &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank"&gt;Reflector&lt;/a&gt;, &lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Synchronization.MetadataStorage.Utility.ConvertDataTypeToSyncMetadataFieldType has the following code:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:e2c2586e-f1b9-4d25-94f1-4439b7ca09de" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;internal static SYNC_METADATA_FIELD_TYPE ConvertDataTypeToSyncMetadataFieldType(Type dataType)
{
    if (dataType == typeof(byte[]))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_BYTEARRAY;
    }
    if (dataType == typeof(string))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_STRING;
    }
    if (dataType == typeof(byte))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_UINT8;
    }
    if (dataType == typeof(ushort))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_UINT16;
    }
    if (dataType == typeof(uint))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_UINT32;
    }
    if (dataType == typeof(ulong))
    {
        return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_UINT64;
    }
    if (dataType != typeof(Guid))
    {
        throw new NotSupportedException(StringResources.NotSupportedDataType);
    }
    return SYNC_METADATA_FIELD_TYPE.SYNC_METADATA_FIELD_TYPE_GUID;
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The answer to this issue is that the Boolean data type is not supported. Unfortunately the documentation for InitializeReplicaMetadata does not to mention this. The way around this is to use a byte value to represent the Boolean state.&lt;/p&gt;

&lt;p&gt;Code that successfully executes now looks like this:&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:4a716789-80a8-4831-959e-b79a4c9110e9" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;List&amp;lt;FieldSchema&amp;gt; customFields = new List&amp;lt;FieldSchema&amp;gt;
                                     {
                                         new FieldSchema("IsContainer", typeof(Byte)),
                                         new FieldSchema("Name", typeof(String), 256),
                                         new FieldSchema("Path", typeof(String), 256)
                                     };
String[] indexFieldNames = new[]
                               {
                                   "IsContainer", "Name", "Path"
                               };
List&amp;lt;IndexSchema&amp;gt; indexFields = new List&amp;lt;IndexSchema&amp;gt;
                                    {
                                        new IndexSchema(indexFieldNames, true)
                                    };

Metadata = MetaStore.InitializeReplicaMetadata(IdFormats, ReplicaId, customFields, indexFields);&lt;/pre&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/1XeR-3oq79I" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/1XeR-3oq79I/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/08/19/Custom-fields-support-with-SqlMetadataStore-in-the-sync-framework.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=35d8899d-d068-426e-89bc-45e6ed2b9ba2</guid>
      <pubDate>Wed, 19 Aug 2009 08:59:52 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=35d8899d-d068-426e-89bc-45e6ed2b9ba2</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=35d8899d-d068-426e-89bc-45e6ed2b9ba2</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/08/19/Custom-fields-support-with-SqlMetadataStore-in-the-sync-framework.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=35d8899d-d068-426e-89bc-45e6ed2b9ba2</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=35d8899d-d068-426e-89bc-45e6ed2b9ba2</feedburner:origLink></item>
    <item>
      <title>Transport connection closed exception with nDumbster</title>
      <description>&lt;p&gt;I have been using nDumbster on a project to unit test sending emails. It has been an interesting experience working with this little tool. It is a great product but has been out of development for a while and &lt;a href="http://blogs.blackmarble.co.uk/blogs/rfennell/archive/2008/09/27/mocking-out-an-email-server.aspx" target="_blank"&gt;has some issues&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The more I started using nDumbster in test runs, the more I was finding that it wasn’t working so well. I was consistently getting the following exception:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Test method [TestName] threw exception:&amp;#160; System.Net.Mail.SmtpException: Failure sending mail. ---&amp;gt;&amp;#160; System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed..&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.CheckCommand.Send(SmtpConnection conn, String&amp;amp; response)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException&amp;amp; exception)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpClient.Send(MailMessage message)&lt;/em&gt;&lt;/p&gt;    &lt;p&gt;&lt;em&gt;System.Net.Mail.SmtpClient.Send(MailMessage message)&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I worked on this one for a while. Without wanting to get my fingers into the nDumbster code, I found a solution that works from within the unit testing code itself. The solution is to create a new instance of the nDumbster SMTP server using a unique port number for each test. This ensures that there is a fresh connection for each test in the test run.&lt;/p&gt;  &lt;p&gt;The unit test code looks like the following.&lt;/p&gt;  &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:4c0d1959-c683-435d-8301-31601c849403" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;/// &amp;lt;summary&amp;gt;
/// Stores the random generator.
/// &amp;lt;/summary&amp;gt;
private static readonly Random RandomPort = new Random(Environment.TickCount);

/// &amp;lt;summary&amp;gt;
/// Stores the SMTP server.
/// &amp;lt;/summary&amp;gt;
private static SimpleSmtpServer _server;

#region Setup/Teardown

/// &amp;lt;summary&amp;gt;
/// Cleans up after running a unit test.
/// &amp;lt;/summary&amp;gt;
[TestCleanup]
public void TestCleanup()
{
    _server.Stop();
    _server = null;
}

/// &amp;lt;summary&amp;gt;
/// Initializes the test.
/// &amp;lt;/summary&amp;gt;
[TestInitialize]
public void TestInitialize()
{
    // HACK: The test must recreate the nDumbster server for each test using a different port number
    // This gets around issues where some tests consistently failed when the whole test class was run because the server
    // was not handling the connection properly. This appears to be the only solution that works.
    Int32 nextPortNumber = RandomPort.Next(1024, 6666);

    _server = SimpleSmtpServer.Start(nextPortNumber);
}

#endregion&lt;/pre&gt;&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/3QMQbNx3lVI" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/3QMQbNx3lVI/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/08/14/Transport-connection-closed-exception-with-nDumbster.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=7f5dc8c7-11d5-4930-85e6-790646988305</guid>
      <pubDate>Fri, 14 Aug 2009 05:49:46 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=7f5dc8c7-11d5-4930-85e6-790646988305</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=7f5dc8c7-11d5-4930-85e6-790646988305</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/08/14/Transport-connection-closed-exception-with-nDumbster.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=7f5dc8c7-11d5-4930-85e6-790646988305</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=7f5dc8c7-11d5-4930-85e6-790646988305</feedburner:origLink></item>
    <item>
      <title>Mocking IUnityContainer and avoiding BadImageFormatException</title>
      <description>&lt;p&gt;There is an issue with mocking IUnityContainer from RhinoMocks. A BadImageFormatException is thrown when you attempt to create a mock or a stub of IUnityContainer. For example: &lt;/p&gt;  &lt;p&gt;   &lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:69d7884f-14df-4f3d-be9a-5f32f7fea983" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;using &lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.Practices.Unity;
using &lt;a href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt;.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace TestProject1
{
    public interface ITestInterface
    {
        void DoSomething();
    }

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void MockingIUnityContainerFailsTest()
        {
            // This throws a BadImageFormatException
            IUnityContainer container = MockRepository.GenerateStub&amp;lt;IUnityContainer&amp;gt;();
            ITestInterface test = MockRepository.GenerateStub&amp;lt;ITestInterface&amp;gt;();

            container.Stub(x =&amp;gt; x.Resolve&amp;lt;ITestInterface&amp;gt;()).Return(test);

            ITestInterface resolvedTest = container.Resolve&amp;lt;ITestInterface&amp;gt;();

            resolvedTest.DoSomething();
        }
    }
}&lt;/pre&gt;&lt;/div&gt;
&lt;/p&gt;

&lt;p&gt;This test results in the following failure: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Test method TestProject1.UnitTest1.MockingIUnityContainerFailsTest threw exception: System.BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B).&lt;/em&gt; &lt;/p&gt;

  &lt;p&gt;System.Reflection.Emit.TypeBuilder._TermCreateClass(Int32 handle, Module module)
    &lt;br /&gt;System.Reflection.Emit.TypeBuilder.CreateTypeNoLock()

    &lt;br /&gt;System.Reflection.Emit.TypeBuilder.CreateType()

    &lt;br /&gt;Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()

    &lt;br /&gt;Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()

    &lt;br /&gt;Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)

    &lt;br /&gt;Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)

    &lt;br /&gt;Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyTypeWithoutTarget(Type theInterface, Type[] interfaces, ProxyGenerationOptions options)

    &lt;br /&gt;Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type theInterface, Type[] interfaces, ProxyGenerationOptions options, IInterceptor[] interceptors)

    &lt;br /&gt;Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type theInterface, Type[] interfaces, IInterceptor[] interceptors)

    &lt;br /&gt;Rhino.Mocks.MockRepository.MockInterface(CreateMockState mockStateFactory, Type type, Type[] extras)

    &lt;br /&gt;Rhino.Mocks.MockRepository.CreateMockObject(Type type, CreateMockState factory, Type[] extras, Object[] argumentsForConstructor)

    &lt;br /&gt;Rhino.Mocks.MockRepository.Stub(Type type, Object[] argumentsForConstructor)

    &lt;br /&gt;Rhino.Mocks.MockRepository.GenerateStub(Type type, Object[] argumentsForConstructor)

    &lt;br /&gt;Rhino.Mocks.MockRepository.GenerateStub[T](Object[] argumentsForConstructor)

    &lt;br /&gt;TestProject1.UnitTest1.MockingIUnityContainerFailsTest() in C:\Users\rprimrose\Documents\Visual Studio 2008\Projects\TestProject1\TestProject1\UnitTest1.&lt;a href="http://www.communityserver.org" target="_blank"&gt;Community Server&lt;/a&gt;: line 19&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can see in the stack trace that this is not actually an issue with RhinoMocks but an issue with Castle. As Moq also uses Castle internally it suffers from the same problem. Many people have &lt;a href="http://www.google.com/search?q=mock+IUnityContainer+BadImageFormatException&amp;amp;hl=en&amp;amp;rls=com.microsoft:en-au&amp;amp;start=0&amp;amp;sa=N" target="_blank"&gt;raised this as an issue and asked for a solution&lt;/a&gt;. There does not seem to be an adequate answer out there other than a solution from &lt;a href="http://weblogs.asp.net/rosherove/archive/2008/04/14/creating-a-automockingcontainer-with-microsoft-unity-pretty-darn-simple.aspx" target="_blank"&gt;Roy Osherove&lt;/a&gt; which is a bit heavy handed for what I want.&lt;/p&gt;

&lt;p&gt;The answer is actually really simple. &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank"&gt;Reflector&lt;/a&gt; indicates the inheritance hierarchy of IUnityContainer as the following.&lt;/p&gt;

&lt;p&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="" border="0" alt="" src="http://www.neovolve.com/image.axd?picture=image_2.png" width="408" height="117" /&gt; &lt;/p&gt;

&lt;p&gt;You can use either of these types to get the expected outcome and avoiding the BadImageFormatException. This exception seems to be an issue with mocking/stubbing the interface rather than its implemented types.&lt;/p&gt;

&lt;p&gt;For example, both of the following tests pass.&lt;/p&gt;

&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:7b848b94-6181-4eca-b4c4-d61027f4600a" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;[TestMethod]
public void MockingUnityContainerBaseSucceedsTest()
{
    IUnityContainer container = MockRepository.GenerateStub&amp;lt;UnityContainerBase&amp;gt;();
    ITestInterface test = MockRepository.GenerateStub&amp;lt;ITestInterface&amp;gt;();

    container.Stub(x =&amp;gt; x.Resolve&amp;lt;ITestInterface&amp;gt;()).Return(test);

    ITestInterface resolvedTest = container.Resolve&amp;lt;ITestInterface&amp;gt;();

    resolvedTest.DoSomething();
}

[TestMethod]
public void MockingUnityContainerSucceedsTest()
{
    IUnityContainer container = MockRepository.GenerateStub&amp;lt;UnityContainer&amp;gt;();
    ITestInterface test = MockRepository.GenerateStub&amp;lt;ITestInterface&amp;gt;();

    container.Stub(x =&amp;gt; x.Resolve&amp;lt;ITestInterface&amp;gt;()).Return(test);

    ITestInterface resolvedTest = container.Resolve&amp;lt;ITestInterface&amp;gt;();

    resolvedTest.DoSomething();
}&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Easy fix.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/RoryPrimrose/~4/U-Jixu3hswk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/RoryPrimrose/~3/U-Jixu3hswk/post.aspx</link>
      <author>Rory</author>
      <comments>http://neovolve.com/post/2009/08/07/Mocking-IUnityContainer-and-avoiding-BadImageFormatException.aspx#comment</comments>
      <guid isPermaLink="false">http://neovolve.com/post.aspx?id=a70e2fb3-7536-4bbb-a70c-412b324b7e32</guid>
      <pubDate>Fri, 07 Aug 2009 08:30:21 +0600</pubDate>
      <category>.Net</category>
      <dc:publisher>Rory</dc:publisher>
      <pingback:server>http://neovolve.com/pingback.axd</pingback:server>
      <pingback:target>http://neovolve.com/post.aspx?id=a70e2fb3-7536-4bbb-a70c-412b324b7e32</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://neovolve.com/trackback.axd?id=a70e2fb3-7536-4bbb-a70c-412b324b7e32</trackback:ping>
      <wfw:comment>http://neovolve.com/post/2009/08/07/Mocking-IUnityContainer-and-avoiding-BadImageFormatException.aspx#comment</wfw:comment>
      <wfw:commentRss>http://neovolve.com/syndication.axd?post=a70e2fb3-7536-4bbb-a70c-412b324b7e32</wfw:commentRss>
    <feedburner:origLink>http://neovolve.com/post.aspx?id=a70e2fb3-7536-4bbb-a70c-412b324b7e32</feedburner:origLink></item>
  </channel>
</rss>
