<?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>David Anderson</title>
	<atom:link href="http://www.danderson.me/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danderson.me</link>
	<description>Independent Software Developer at DCOM Productions writing about C# and .NET.</description>
	<lastBuildDate>Tue, 15 May 2012 14:09:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Fixing the SyntaxHighlighter Evolved WordPress plugin&#8217;s font-size issues with Fluid-Blue theme.</title>
		<link>http://www.danderson.me/2012/05/fixing-the-syntaxhighlighter-evolved-wordpress-plugins-font-size-issues-with-fluid-blue-theme/</link>
		<comments>http://www.danderson.me/2012/05/fixing-the-syntaxhighlighter-evolved-wordpress-plugins-font-size-issues-with-fluid-blue-theme/#comments</comments>
		<pubDate>Sun, 13 May 2012 21:50:13 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.danderson.me/?p=691</guid>
		<description><![CDATA[For WordPress, Fluid-Blue is a popular theme amongst the technical community because its intrinsically great for writing technical articles. For posting code, I use the SyntaxHighlighter Evolved plugin. The problem is that the CSS for the Fluid-Blue theme conflicts with the CSS for the plugin. There are two main conflicts with the theme and plugin. [...]]]></description>
			<content:encoded><![CDATA[<p>For <a href="http://www.wordpress.org" target="_blank">WordPress</a>, <a href="http://srinig.com/wordpress/themes/fluid-blue/" target="_blank">Fluid-Blue</a> is a popular theme amongst the technical community because its intrinsically great for writing technical articles. For posting code, I use the <a href="http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/" target="_blank">SyntaxHighlighter Evolved</a> plugin. The problem is that the CSS for the Fluid-Blue theme conflicts with the CSS for the plugin.</p>
<p>There are two main conflicts with the theme and plugin.</p>
<ol>
<li>The syntax highlighter&#8217;s font size is too small</li>
<li>The syntax highlighter&#8217;s lines in the left gutter and code don&#8217;t line up</li>
</ol>
<p>I came across <a href="http://matthewturland.com/2012/02/13/wordpress-syntaxhighlighter-font-size-fix/" target="_blank">this blog post by Matthew Turland</a>, which talks about fixing the font-size, and it does, but it does not fix the second issue with the lines matching up. After looking into the problem, it turns out that there are other elements of the syntax highlighter that need their font sizes adjusted as well.</p>
<p>You can modify the theme stylesheet directly, but instead we are going to create a child theme. The reason for this is to abstract our changes away from the original theme so we don&#8217;t have to deal with so much CSS.</p>
<p>To do this, go to your WordPress themes folder on your FTP (<code>wordpress_root/wp-content/themes/</code>) where <code>wordpress_root</code> is your domain and root path to your WordPress directory. Create a new folder and call it <code>fluid-blue-syntaxhighlighter</code>. You can actually call this whatever you want, but the idea is to be consistent with naming where <code>fluid-blue</code> is the name of the theme we want to derive from, and <code>syntaxhighlighter</code> is just the name of the child theme.</p>
<p>Next, create a new css file named <code>style.css</code> and use the following code.</p>
<pre class="brush: css; highlight: [3]; title: css; notranslate">/*Theme Name:
  Fluid Blue (Custom)
  Template: fluid-blue
*/ 

@import url(&quot;../fluid-blue/style.css&quot;);</pre>
<p>The CSS comment actually is a configuration section that does one simple thing; it tells WordPress the parent theme we are deriving from. Now we can apply the style fixes for the syntax highlighter plugin.</p>
<pre class="brush: css; title: css; notranslate">body .syntaxhighlighter a,
body .syntaxhighlighter div,
body .syntaxhighlighter code,
body .syntaxhighlighter table,
body .syntaxhighlighter table td,
body .syntaxhighlighter table tr,
body .syntaxhighlighter table tbody,
body .syntaxhighlighter table thead,
body .syntaxhighlighter table caption,
body .syntaxhighlighter textarea,
body .syntaxhighlighter .gutter {
    font-size: 12px !important;
    line-height: 13px !important;
}</pre>
<p>Set the <code>font-size</code> to whatever you want it to be, and set the <code>line-height</code> to be either the same, or one pixel larger. I found that the alignment seemed to look the best with it increased by one pixel.</p>
<p>Now upload <code>style.css</code> to your child theme you created earlier.</p>
<p>The last step is to actually activate the theme. Go to your WordPress Appearance section, and click &#8216;Activate&#8217; on your child theme. If your child theme does not appear, then you may not have created it in the correct location on your FTP.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/fixing-the-syntaxhighlighter-evolved-wordpress-plugins-font-size-issues-with-fluid-blue-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Working with the WPF TextBlock control.</title>
		<link>http://www.danderson.me/2012/05/working-with-the-wpf-textblock-control/</link>
		<comments>http://www.danderson.me/2012/05/working-with-the-wpf-textblock-control/#comments</comments>
		<pubDate>Sun, 13 May 2012 17:35:05 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Formatting]]></category>
		<category><![CDATA[TextBlock]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[Xaml]]></category>

		<guid isPermaLink="false">http://www.danderson.me/?p=600</guid>
		<description><![CDATA[Introduction Setting a TextBlock&#8217;s Content Formatting Text Using Controls with Formatted Text Introduction In WPF there are two very similar controls Label and TextBlock, and I&#8217;m going to cover TextBlock and why its so useful. First, what is the TextBlock control? A first look at the Msdn documentation. Provides a lightweight control for displaying small [...]]]></description>
			<content:encoded><![CDATA[<p><a href="#introduction">Introduction</a><br />
<a href="#settingcontent">Setting a TextBlock&#8217;s Content</a><br />
<a href="#formattingtext">Formatting Text</a><br />
<a href="#controlruns">Using Controls with Formatted Text</a></p>
<p><a name="introduction" /></p>
<p><strong>Introduction</strong></p>
<p>In WPF there are two very similar controls <code>Label</code> and <code>TextBlock</code>, and I&#8217;m going to cover <code>TextBlock</code> and why its so useful. First, what is the <code>TextBlock</code> control? A first look at the Msdn documentation.</p>
<blockquote><p>Provides a lightweight control for displaying small amounts of flow content.</p></blockquote>
<p>Well, that doesn&#8217;t tell that much about the control. A more accurate description would be that its a lightweight control for displaying various forms of formatted text and controls in a flow layout. Specifically, the <code>TextBlock</code> control can contain other controls, and arbitrary text that you can format with different font styles, colors, and brushes. Because it can contain other controls, it is actually much more than a `Text`Block, and I&#8217;m not sure why they named it <code>TextBlock</code> considering.</p>
<p><a name="settingcontent" /></p>
<p><strong>Setting a TextBlock&#8217;s Content</strong></p>
<p>For demonstration, I will start with a small WPF Windows Application that contains just a <code>TextBlock</code> control containing the text <em>Hello World!</em>.</p>
<pre class="brush: xml; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            Hello World!
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_608" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_HelloWorld.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_HelloWorld-300x200.png" alt="TextBlockDemo HelloWorld 300x200 Working with the WPF TextBlock control." title="Hello World!" width="300" height="200" class="size-medium wp-image-608" /></a><p class="wp-caption-text">An empty window with a TextBlock</p></div>
<p>There are two ways you can set text for a <code>TextBlock</code>. The first is the most obvious, and that is to set the <code>Text</code> property.</p>
<pre class="brush: xml; title: Xaml; notranslate">&lt;TextBlock Text=&quot;Hello World!&quot; HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;</pre>
<p>The second is by setting the inner value of the control like I did in the demo application. Both methods give the same result for displaying <em>Hello World!</em>, but only setting the inner value of the <code>TextBlock</code> control gives us access to the true potential of the control. The <code>Text</code> property itself can only be used to display an arbitrary <code>System.String</code>. Shown below is the source code from the <code>TextBlock</code> metadata of its <code>Text</code> property.</p>
<pre class="brush: csharp; title: C#; notranslate">//
// Summary:
//     Gets or sets the text contents of a System.Windows.Controls.TextBlock.
//
// Returns:
//     The text contents of this System.Windows.Controls.TextBlock. Note that all
//     non-text content is stripped out, resulting in a plain text representation
//     of the System.Windows.Controls.TextBlock contents. The default is System.String.Empty.
[Localizability(LocalizationCategory.Text)]
public string Text { get; set; }</pre>
<p>Because the <code>TextBlock</code> can contain multiple controls by using its inner value, we can add things like buttons or other controls.</p>
<pre class="brush: xml; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            Hello World!
            &lt;Button Content=&quot;Click me!&quot; /&gt;
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_639" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithButton.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithButton-300x200.png" alt="TextBlockDemo TextWithButton 300x200 Working with the WPF TextBlock control." title="TextBlockDemo_TextWithButton" width="300" height="200" class="size-medium wp-image-639" /></a><p class="wp-caption-text">A TextBlock containing text along with a Button control.</p></div>
<p>One of the most common questions from those just entering the WPF world is <em>why doesn&#8217;t the button display on a new line even though in the Xaml the <code>Button</code> element is on its own line?</em> Placing elements on a new line doesn&#8217;t necessarily do anything, and for a <code>TextBlock</code> control, adding a new line is actually done using the <code>LineBreak</code> element.</p>
<pre class="brush: xml; highlight: [8]; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            Hello World!
            &lt;LineBreak /&gt;
            &lt;Button Content=&quot;Click me!&quot; /&gt;
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_641" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithButtonAndLineBreak.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithButtonAndLineBreak-300x200.png" alt="TextBlockDemo TextWithButtonAndLineBreak 300x200 Working with the WPF TextBlock control." title="TextBlockDemo_TextWithButtonAndLineBreak" width="300" height="200" class="size-medium wp-image-641" /></a><p class="wp-caption-text">A TextBlock control with text, a button, and a line break.</p></div>
<p>I won&#8217;t cover any more about nested controls in the <code>TextBlock</code>. Once you understand that a control can contain other controls, the rest depends on your understanding of understanding the layout and styling mechanisms of WPF. The usefulness of truly comes from the ability to format strings of text without using multiple controls.</p>
<p><a name="formattingtext" /></p>
<p><strong>Formatting Text</strong></p>
<p>Formatting text is done using an element called a <code>Run</code> which is defined as a inline-level flow content element intended  to contain a run of formatted or unformatted text. Using a <code>Run</code>, you can style seperate segments of text using colors, brushes, and styles.</p>
<pre class="brush: xml; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            &lt;Run Foreground=&quot;Red&quot;&gt;Hello&lt;/Run&gt;
            &lt;Run Foreground=&quot;Blue&quot;&gt;World!&lt;/Run&gt;
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_669" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_RedAndBlueRun.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_RedAndBlueRun-300x200.png" alt="TextBlockDemo RedAndBlueRun 300x200 Working with the WPF TextBlock control." title="TextBlockDemo_RedAndBlueRun" width="300" height="200" class="size-medium wp-image-669" /></a><p class="wp-caption-text">A TextBlock containing the text &#039;Hello World!&#039; split into two runs, one red and one blue.</p></div>
<p>You can see that it was very easy to style the text to be red and blue. Now let&#8217;s add a <code>LinearGradientBrush</code> to the second run and give it a larger font with a bold style.</p>
<pre class="brush: xml; highlight: [11]; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            &lt;Run Foreground=&quot;Red&quot;&gt;Hello&lt;/Run&gt;

            &lt;LineBreak /&gt;

            &lt;Run Text=&quot;World!&quot; FontSize=&quot;24pt&quot; FontWeight=&quot;Bold&quot;&gt;
                &lt;Run.Foreground&gt;
                    &lt;LinearGradientBrush StartPoint=&quot;0,1&quot; EndPoint=&quot;0,0&quot;&gt;
                        &lt;GradientStop Offset=&quot;0&quot; Color=&quot;Navy&quot; /&gt;
                        &lt;GradientStop Offset=&quot;1&quot; Color=&quot;DodgerBlue&quot; /&gt;
                    &lt;/LinearGradientBrush&gt;
                &lt;/Run.Foreground&gt;
            &lt;/Run&gt;
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_672" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_RunGradient.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_RunGradient-300x200.png" alt="TextBlockDemo RunGradient 300x200 Working with the WPF TextBlock control." title="TextBlockDemo_RunGradient" width="300" height="200" class="size-medium wp-image-672" /></a><p class="wp-caption-text">A TextBlock run with its Foreground set to a LinearGradientBrush</p></div>
<p>Just like the <code>TextBlock</code>, a <code>Run</code> can contain its text in either its <code>Text</code> property, or its inner value. Since we want to use its inner value to set some text effects, it was moved from the inner value to the <code>Text</code> property. The <code>FontSize</code> and <code>FontWeight</code> properties were also added, along with our <code>Run.Foreground</code> element that contains our linear gradient effect.</p>
<p><a name="controlruns" /></p>
<p><strong>Using Controls with Formatted Text</strong></p>
<p>Often times you may want to do something like have a piece of text actually contain a link to some resource. I had a need for this myself in one of my dialogs in my licensing modules; I need it to display a link to a product page. A <code>TextBlock</code> can contain both controls and runs, which makes for great flexibility. A <code>Run</code> however, cannot contain a control so its important to make note of that.</p>
<pre class="brush: xml; title: Xaml; notranslate">&lt;Window x:Class=&quot;TextBlockDemo.MainWindow&quot;
        xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;TextBlock HorizontalAlignment=&quot;Stretch&quot; VerticalAlignment=&quot;Top&quot;&gt;
            &lt;Run Text=&quot;This is some text containing a &quot; /&gt;
            &lt;Hyperlink NavigateUri=&quot;http://www.danderson.me/&quot;&gt;link to a page.&lt;/Hyperlink&gt;
        &lt;/TextBlock&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;</pre>
<div id="attachment_684" class="wp-caption alignnone" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithLink.png"><img src="http://www.danderson.me/wp-content/uploads/2012/05/TextBlockDemo_TextWithLink-300x200.png" alt="TextBlockDemo TextWithLink 300x200 Working with the WPF TextBlock control." title="TextBlockDemo_TextWithLink" width="300" height="200" class="size-medium wp-image-684" /></a><p class="wp-caption-text">A TextBlock containing a HyperLink.</p></div>
<p>The cool thing about this is that because a <code>HyperLink</code> is its own control, it can contain its own styling and behaviors.</p>
<p>There&#8217;s not much else to say about the <code>TextBlock</code> because it really is a simple control. It&#8217;s just really flexible and when used correctly can be a very easy way to display lots of formatted text to a user. The ability to contain controls that can also have their own styles and behaviors is really cool, but I still think the WPF team should have chosen a better name than <code>TextBlock</code>, because its much more than just arbitrary text.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/working-with-the-wpf-textblock-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio 11 RC User Interface Updates, Developer Experience, and Color changes.</title>
		<link>http://www.danderson.me/2012/05/visual-studio-11-rc-user-interface-updates-developer-experience-and-color-changes/</link>
		<comments>http://www.danderson.me/2012/05/visual-studio-11-rc-user-interface-updates-developer-experience-and-color-changes/#comments</comments>
		<pubDate>Sat, 12 May 2012 05:36:38 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[beta]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[RC]]></category>
		<category><![CDATA[ReleaseCandidate]]></category>
		<category><![CDATA[UX]]></category>
		<category><![CDATA[VisualStudio]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=580</guid>
		<description><![CDATA[The Visual Studio team has posted some updates on the Visual Studio blog regarding the feedback we have all been providing them about the beta. Personally, I don&#8217;t mind the new Visual Studio themes (the light and dark themes), but the thing I don&#8217;t like is that Microsoft has seemed to forget that UX guidelines [...]]]></description>
			<content:encoded><![CDATA[<p>The Visual Studio team has <a title="Visual Studio 11 User Interface Updates Coming in RC" href="http://blogs.msdn.com/b/visualstudio/archive/2012/05/08/visual-studio-11-user-interface-updates-coming-in-rc.aspx" target="_blank">posted some updates on the Visual Studio blog</a> regarding the feedback we have all been providing them about the beta.</p>
<p>Personally, I don&#8217;t mind the new Visual Studio themes (the light and dark themes), but the thing I don&#8217;t like is that Microsoft has seemed to forget that UX guidelines exist (including their own UX guidelines). The community of developers provided their feedback how they disliked the all-caps docking window titles, and Microsoft did listen and fix it, but it seems like that didn&#8217;t matter because they went and changed the main menu&#8217;s to all-caps instead. Instead of really fixing the problem, they really just moved it to a different part of the UI. I really hope this changes in the RC, and I really hope it gets fixed before RTM.</p>
<div id="attachment_582" class="wp-caption alignleft" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/vs11beta.png"><img class="size-medium wp-image-582" title="Visual Studio 11 Beta" src="http://www.danderson.me/wp-content/uploads/2012/05/vs11beta-300x187.png" alt="vs11beta 300x187 Visual Studio 11 RC User Interface Updates, Developer Experience, and Color changes." width="300" height="187" /></a><p class="wp-caption-text">Visual Studio 11 Beta</p></div>
<div id="attachment_583" class="wp-caption alignleft" style="width: 310px"><a href="http://www.danderson.me/wp-content/uploads/2012/05/vs11rc.png"><img class="size-medium wp-image-583" title="Visual Studio 11 Release Candidate" src="http://www.danderson.me/wp-content/uploads/2012/05/vs11rc-300x187.png" alt="vs11rc 300x187 Visual Studio 11 RC User Interface Updates, Developer Experience, and Color changes." width="300" height="187" /></a><p class="wp-caption-text">Visual Studio 11 Release Candidate</p></div>
<div style="clear: both;"></div>
<p>The two images above are a comparison between the two interfaces from beta to release candidate, and there isn&#8217;t that much change. Color was added, but it is minimal. For anyone who has done graphics in Photoshop, looking at the images you know that the amount of work that went into the color changes was almost none. We&#8217;ll have to wait and see what will become of Visual Studio 11 by RTM based on the communities feedback.</p>
<p>In my own opinion, it really seems like Microsoft is promoting the idea of Metro into all their products. And again in my opinion, I really dislike the Metro ideology. From a developer standpoint, it seems like going back to Windows 3.1 with interfaces dumbed down and restricted for non-power users, and from a customer standpoint its threatening the desktop business environment. It seems that the industry might be headed in the wrong direction with UX patterns. The stuff going on under the hood and all the plumbing written by developers is still some of the most amazing work we&#8217;ve seen in the industry to date, but the way all that hard work is being portrayed as display is worrisome.</p>
<p>There are lots of mixed feelings and opinions from developers about Windows 8, Metro, Visual Studio 11, and even the new Microsoft Office in the works, but I hope that the majority developer feedback takes precedence and that Microsoft listens to its oldest, most valuable customers: software developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/visual-studio-11-rc-user-interface-updates-developer-experience-and-color-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Avoiding a deadlock when creating a STA thread and using Dispatcher.</title>
		<link>http://www.danderson.me/2012/05/avoiding-a-deadlock-when-creating-a-sta-thread-and-using-dispatcher/</link>
		<comments>http://www.danderson.me/2012/05/avoiding-a-deadlock-when-creating-a-sta-thread-and-using-dispatcher/#comments</comments>
		<pubDate>Tue, 08 May 2012 17:42:39 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Deadlock]]></category>
		<category><![CDATA[Dispatcher]]></category>
		<category><![CDATA[STA]]></category>
		<category><![CDATA[Threading]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=556</guid>
		<description><![CDATA[I have always been pretty articulate and careful when writing multi-threading code, but today I wrote my first deadlock that had me baffled for a few minutes. I&#8217;m working on a licensing dll that handles a lot of processing, and it also handles some user interface display using WPF Windows. I cannot guaruntee whether or [...]]]></description>
			<content:encoded><![CDATA[<p>I have always been pretty articulate and careful when writing multi-threading code, but today I wrote my first deadlock that had me baffled for a few minutes. I&#8217;m working on a licensing dll that handles a lot of processing, and it also handles some user interface display using WPF Windows. I cannot guaruntee whether or not the calling thread will be a single-threaded apartment, because the assembly that implements it might be a console or a window, but the assembly doesn&#8217;t know which, or which threading model it uses. The good news is that <code>System.Threading</code> provides very rich types to be able to check for this as well as handle it.</p>
<p>First lets take a look at actually checking for the threading model, and creating an STA thread if needed.</p>
<pre class="brush: csharp; title: Code; notranslate">if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) {
    Thread thread = new Thread(() =&gt; {
        // ...
    });

    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
}</pre>
<p>You can see that the code to check for the current threading apartment isn&#8217;t anything hard, and neither is setting the apartment state. Now my requirement was that the WPF Window be shown modal by calling <code>Window.ShowDialog</code> so I could consume the <code>DialogResult</code> and continue processing in the licensing service. To do this I created the <code>Window</code> in the newly created STA thread.</p>
<pre class="brush: csharp; title: Code; notranslate">if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) {
    ActivateWindowController controller = new ActivateWindowController();
    ActivateWindow window = null;

    bool? dialogResult = null;

    Thread thread = new Thread(() =&gt; {
        window = new ActivateWindow(controller);
        dialogResult = window.ShowDialog();
    });

    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
}</pre>
<p>There&#8217;s nothing too exciting about any of this either. I&#8217;m using the Model-View-Controller (MVC) pattern so I have a <code>ActivateWindowController</code> that gets passed to the <code>ActivateWindow</code> constructor. Because we need the <code>Window</code> to run in a single-threaded apartment, I do the actual instantiation in the new <code>Thread</code>. Then I make a call to <code>ShowDialog()</code> and consume the result. The last bit is adding <code>thread.Join();</code> so the calling thread is blocked until the new thread terminates, which is when the dialog is closed.</p>
<p>Now I&#8217;ll try to explain what <code>ActivateWindowController</code> does as best as I can. When <code>ActivateWindow</code> is loaded, the WPF stack invokes the <code>Loaded</code> event handler. The code isn&#8217;t anything special, so I&#8217;ll just show it.</p>
<pre class="brush: csharp; title: Code; notranslate">public partial class ActivateWindow : Window
{
    /// &lt;summary&gt;
    /// Initializes a new instance of the DCOMProductions.Licensing.Windows.LicenseWindow class.
    /// &lt;/summary&gt;
    public ActivateWindow(ActivateWindowController controller) {
        InitializeComponent();
        _controller = controller;
    }

    #region Controller Members

    private ActivateWindowController _controller;

    private void Window_Loaded(object sender, RoutedEventArgs e) {
        _controller.ActivateComplete += ActivateComplete;
        _controller.Activate();
    }

    private void ActivateComplete(object sender, ActivateWindowController.ActivateEventArgs e) {
        DialogResult = e.Result == ActivationResult.Passed ? true : false;
    }

    #endregion
}</pre>
<p>When the <code>Loaded</code> event handler is invoked, a call to <code>ActivateWindowController.Activate()</code> is made. What this method does is spin off a new <code>Task</code> by calling <code>Task.Factory.StartNew(...)</code> and consumes a WCF service. In short, it means another thread. When the task completes, it invokes <code>Task.ContinueWith(...)</code> which is responsible for wrapping up the result and delegating everything to the proper thread.</p>
<pre class="brush: csharp; highlight: [5]; title: Code; notranslate">.ContinueWith((task) =&gt; {
    CloseDialogCallback method = new CloseDialogCallback(() =&gt; {
        OnActivateComplete(new ActivateEventArgs(result));
    });
    _Dispatcher.BeginInvoke(method, null);
});</pre>
<p>Now it is important to note here that <code>_Dispatcher</code> is a private instance that was initialized in the constructor of <code>ActivateWindowController</code>. In short, the dispatcher lives on the UI thread of the <code>Window</code>. The dispatcher is required to delegate calls to the correct thread, in this case we want to delegate the callback <code>method</code> to the UI thread. And remember, the UI thread is the STA thread I created earlier.</p>
<p>I highlighted the last line, because this is where the deadlock is introduced. When <code>_Dispatcher.BeginInvoke(method, null);</code> is called, it schedules asynchronously the callback to be executed on the thread that the dispatcher was created on. And remember, the thread that <code>_Dispatcher</code> was created on is the same thread that the <code>ActivateWindowController</code> instance was created on. Let&#8217;s double check that.</p>
<pre class="brush: csharp; highlight: [2]; title: Code; notranslate">if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA) {
    ActivateWindowController controller = new ActivateWindowController();
    ActivateWindow window = null;

    bool? dialogResult = null;

    Thread thread = new Thread(() =&gt; {
        window = new ActivateWindow(controller);
        dialogResult = window.ShowDialog();
    });

    thread.SetApartmentState(ApartmentState.STA);
    thread.Start();
    thread.Join();
}</pre>
<p>Well, hopefully by now you realize the problem and why there is a deadlock. <code>ActivateWindowController</code> is <em>not</em> being instantiated on our STA thread. So what&#8217;s happening here is when <code>_Dispatcher.BeginInvoke</code> is called, it is scheduling the callback to execute on the same thread we told to block by calling <code>thread.Join()</code>. Because that thread is blocked and the dialog can&#8217;t return until the callback is executed by the dispatcher, I have a blocked thread and a scheduled callback that will never run; eg. a deadlock.</p>
<p>The fix is to instantiate <code>ActivateWindowController</code> on the STA thread I created which is where we want the dispatcher to delegate the callback to anyway. This resolves the deadlock problem. It&#8217;s important to watch out for little quirks like this. It didn&#8217;t take me long to realize what created the deadlock, but I think on most days it would have taken me much longer to figure it out. The most important thing to remember is that this is not specific to a <code>Dispatcher</code>, and that it applies to multi-threading regardless.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/avoiding-a-deadlock-when-creating-a-sta-thread-and-using-dispatcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Showing a splash screen in WPF from an external assembly or class library.</title>
		<link>http://www.danderson.me/2012/05/showing-a-splash-screen-in-wpf-from-an-external-assembly-or-class-library/</link>
		<comments>http://www.danderson.me/2012/05/showing-a-splash-screen-in-wpf-from-an-external-assembly-or-class-library/#comments</comments>
		<pubDate>Tue, 08 May 2012 13:04:55 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[assembly]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Class Library]]></category>
		<category><![CDATA[Splash]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://www.danderson.me/?p=516</guid>
		<description><![CDATA[This isn&#8217;t anything special, but the documentation on Msdn for System.Windows.SplashScreen is lacking. Basically I am writing a licensing system and during debugging the WPF stack can take many seconds to load. When making changes to this system sometimes it may result in a failure, but I may not see it for a few seconds. [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t anything special, but the documentation on Msdn for <code><a title="SplashScreen Class (System.Windows)" href="http://msdn.microsoft.com/en-us/library/system.windows.splashscreen.aspx" target="_blank">System.Windows.SplashScreen</a></code> is lacking. Basically I am writing a licensing system and during debugging the WPF stack can take many seconds to load. When making changes to this system sometimes it may result in a failure, but I may not see it for a few seconds. I wanted something to display during this time period so I know at least something is going on.</p>
<p>I knew that WPF has built-in support for splash screens by setting the Build Action of an image in my project to Splash Screen in the properties window, but the problem is that this only works for the project the image is embedded into, and only if its a WPF Application project. My requirements are that I can display the splash screen from my licensing dll (class library) when my licensing service is invoked. This means that the licensing dll would contain the image to display, and contain the logic to show the splash.</p>
<p>Luckily, <code>SplashScreen</code> exposes a <code>SplashScreen(Assembly, String)</code> constructor which allows you to do just this. To accomplish this task, all you need to do is add your image to your class library project, set its build action to <em>Splash Screen</em>, and then write three lines of code.</p>
<pre class="brush: csharp; title: Code; notranslate">Assembly asm = Assembly.GetAssembly(GetType());
SplashScreen splash = new SplashScreen(asm, &quot;SplashScreen.png&quot;);
splash.Show(true);</pre>
<p>The first line is simple; we are just getting the assembly that contains the splash resource (in this case my licensing library). The second line takes the assembly as an argument, and we pass in the name of the image. Next we simply call <code>splash.Show(true);</code> which actually displays the image, and because we passed in <code>true</code> as the argument, it will automatically be closed by the WPF stack once the first window is constructed, loaded, and displayed.</p>
<blockquote><p>Make sure that you add your image to the root of your project, so that the WPF stack can find it.</p></blockquote>
<p>I haven&#8217;t looked into it because I don&#8217;t want to spend a lot of time on a task that doesn&#8217;t mean much, but placing the image at other hierarchical locations in your project structure can cause the embedded resource path string to change, and it may not be found by the WPF stack internally. It&#8217;s probably possible to specify a qualified path using the second constructor parameter, but I was not able to get it to work using a fully qualified resource path string.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/showing-a-splash-screen-in-wpf-from-an-external-assembly-or-class-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting a stream to a resource without copying the contents into memory.</title>
		<link>http://www.danderson.me/2012/05/getting-a-stream-to-a-resource-without-copying-the-contents-into-memory/</link>
		<comments>http://www.danderson.me/2012/05/getting-a-stream-to-a-resource-without-copying-the-contents-into-memory/#comments</comments>
		<pubDate>Tue, 08 May 2012 08:51:47 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[embedded]]></category>
		<category><![CDATA[Manifest]]></category>
		<category><![CDATA[Memory]]></category>
		<category><![CDATA[resource]]></category>
		<category><![CDATA[ResourceManager]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=440</guid>
		<description><![CDATA[If you have ever added a resource file to your project through the Project Properties &#62; Resources tab, then you have used a ResourceManager. The resource manager allows you to access resources in your application simply through a static resource manager. This line of code should look familiar. This is not just convenient, it&#8217;s just [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever added a resource file to your project through the Project Properties &gt; Resources tab, then you have used a <code>ResourceManager</code>. The resource manager allows you to access resources in your application simply through a static resource manager. This line of code should look familiar.</p>
<pre class="brush: csharp; title: Code; notranslate">string message = Properties.Resources.MyDialogText;</pre>
<p>This is not just convenient, it&#8217;s just plain easy. The problem is that when something is just plain easy, there are often tradoffs, and here there is a big one. Let&#8217;s assume we have a binary resource (a file) that is 7764480 bytes (7.40 megabytes) called &#8216;Bootstrapper.exe&#8217;. Now normally you would get the resource just by doing <code>byte[] bytes = Properties.Resources.Bootstrapper</code>. What happens here is you are invoking an instance of <code>ResourceManager</code> that returns the bytes to our Bootstrapper.exe file. The tradoff of such an easy way of getting the resource, is that it just created a copy of the data into memory, adding 7.40 megabytes to our application&#8217;s Working Set memory. Let&#8217;s look at a bare-bone sample application.</p>
<pre class="brush: csharp; title: Code; notranslate">namespace ResourceManagerSample
{
    using System;

    internal static class Program
    {
        public static void Main(string[] args) {
            Byte[] bytes = Properties.Resources.Bootstrapper;
        }
    }
}</pre>
<p>Stepping through this code and stopping on line 11, just before the statement is executed, the application&#8217;s working set is 47,964 bytes. Execute the statement by stepping to the end of the method body, and the working set just increased from 47,964 bytes to 63,364 bytes. What happened is the <code>ResourceManager</code> just returned us a copy of the binary resource contents. If you were working with a binary resource that was say, a gigabyte in size, your application&#8217;s working set memory would have just increased by a gigabyte.</p>
<p>Let&#8217;s take a look at why this happens by looking at the internals of the <code>ResourceManager</code> class. The two main methods we are interested in are <code>Object GetObject(String, CultureInfo, Boolean)</code> and <code>UnmanagedMemoryStream GetStream(String, CultureInfo)</code>.</p>
<pre class="brush: csharp; title: Code; notranslate">private Object GetObject(String name, CultureInfo culture, bool wrapUnmanagedMemStream) {
    ...
    Object value = rs.GetObject(name, _ignoreCase);
    ...
}</pre>
<p>I stripped the method down to the important line, which is <code>rs.GetObject(name, _ignoreCase);</code>. What happens here is the <code>ResourceManager</code> makes a call to <code>ResourceSet.GetObject</code>, which is what actually gets the resource as a <code>System.Object</code>. The internals of the <code>ResourceSet</code> are not that interesting either, because all it does is get the object from a <code>HashTable</code>.</p>
<pre class="brush: csharp; title: Code; notranslate">public virtual Object GetObject(String name, bool ignoreCase)
{
    Hashtable copyOfTable = Table;  // Avoid a race with Dispose
    if (copyOfTable == null)
        throw new ObjectDisposedException(null, Environment.GetResourceString(&quot;ObjectDisposed_ResourceSet&quot;));
    if (name==null)
        throw new ArgumentNullException(&quot;name&quot;); 

    Object obj = copyOfTable[name];
    ...
    return caseTable[name];
}</pre>
<p>As you can see, the public call in <code>ResourceManager</code> simply calls into <code>ResourceSet</code> which returns the actual resource as an object. Because its returning the actual object, memory is allocated for the resource, thus increasing our working set. I won&#8217;t show the internals of <code>ResourceManager.GetStream</code> because all that does is actually make a call to <code>GetObject</code> as well, so it boils down to the same thing. The difference is that <code>GetObject</code> can return just an object (a <code>System.String</code> for example), or it can return an <code>UnmanagedMemoryStream</code>. <code>GetStream</code> obviously only returns a stream.</p>
<p>Intrinsically the problem is that <code>ResourceManager</code> creates a heavy memory footprint, and it isn&#8217;t flexible enough to grab only a pointer to the resource instead of an actual instance copy. We can get around this problem by using <strong>embedded resources</strong>.</p>
<p>Embedded resources are embedded into the assembly manifest at compile-time and accessible directly through the assembly. Working with ResX resource files, resources are still embedded but are accessible through a <code>ResourceManager</code> which I already discussed. ResX resources are not available directly through the assembly such as calling <code>Assembly.GetManifestResourceNames</code>. In either case, resources still get embedded to the assembly at compile-time, but each is accessible in a different way.</p>
<p>With avoiding using a ResX resource file and <code>ResourceManager</code>, you can set the <em>Build Action</em> of the resource by right-clicking the file, and setting <em>Build Action</em> in the properties Window to <em>Embedded Resource</em>.</p>
<blockquote><p>It&#8217;s important that you do not use a ResX resource file <em>and</em> set the resource to embedded. This will result in you having the same resource embedded twice, increasing the size of your assembly 2x.</p></blockquote>
<p>With embedded resources, we can access them by using the <code>Assembly</code> class, and calling <code>Assembly.GetManifestResourceNames()</code> and <code>Assembly.GetManifestResourceStream(String)</code>.</p>
<pre class="brush: csharp; highlight: [5]; title: Code; notranslate">private static UnmanagedMemoryStream GetResourceStream(String name) {
    Assembly assembly = Assembly.GetExecutingAssembly();

    string[] resources = assembly.GetManifestResourceNames();
    string resource = resources.SingleOrDefault(r =&gt; r.EndsWith(name, StringComparison.CurrentCultureIgnoreCase));

    if (resource == null) {
        throw new System.ArgumentException(&quot;The specified resource does not exist in the assembly manifest.&quot;, &quot;name&quot;);
    }

    return (UnmanagedMemoryStream)assembly.GetManifestResourceStream(resource);
}</pre>
<p>It&#8217;s important to note how embedded resource names are stored in the manifest. When you set the build action on a file in your project to Embedded Resource, a resource name is created in the manifest that uniquely identifies the resource. The name will take on the project and foldier hierarchy and is in the format of a namespace. If the Bootstrapper.exe resource is in the root directory of the project named <em>RresourceManagerSample</em>, the resource identifier will be <code>ResourceManagerSample.Bootstrapper.exe</code>. And if you had it in a subfolder of the project called <em>Resources</em> it would be <code>ResourceManagerSample.Resources.Bootstrapper.exe</code>.</p>
<p>In the example method I wrote it takes a <code>System.String name</code> parameter, and checks the end of each resource string for a match, and throws a <code>System.ArgumentException</code> if the resource does not exist. The rest of the method is simple, because it just returns an <code>UnmanagedMemoryStream</code> by calling <code>assembly.GetManifestResourceStream()</code>.</p>
<p>The whole point of this is that by using embedded resources and reflection, we get the resource as an <code>UnmanagedMemoryStream</code> without having the entire resource copied into memory. Before when using a <code>ResourceManager</code> remember that it would copy the entire resource into memory. This method does not do that, and looking at the internals of <code>Assembly.GetManifestResourceStream()</code> tells us why.</p>
<pre class="brush: csharp; highlight: [4]; title: Code; notranslate">internal unsafe virtual Stream GetManifestResourceStream(String name, ref StackCrawlMark stackMark, bool skipSecurityCheck)
{
    ulong length = 0;
    byte* pbInMemoryResource = GetResource(name, out length, ref stackMark, skipSecurityCheck); 

    if (pbInMemoryResource != null) {
        if (length &gt; Int64.MaxValue)
            throw new NotImplementedException(Environment.GetResourceString(&quot;NotImplemented_ResourcesLongerThan2^63&quot;));
        return new UnmanagedMemoryStream(pbInMemoryResource, (long)length, (long)length, FileAccess.Read, true);
    }

    return null;
}</pre>
<p>You can immediately see that instead of obtaining an instance copy of the resource, you get a nice pointer to the resource instead. Looking further into the implementation you can see that the call to <code>GetResource</code> actually makes a call to an external method called <code>_GetResource</code>.</p>
<pre class="brush: csharp; title: Code; notranslate">[MethodImplAttribute(MethodImplOptions.InternalCall)]
private unsafe extern byte* _GetResource(String resourceName, out ulong length,
                                        ref StackCrawlMark stackMark,
                                        bool skipSecurityCheck);</pre>
<p>If you don&#8217;t know what <code>extern</code> does, it is easily explained in 10.6.7 of the C# specification.</p>
<blockquote><p>When a method declaration includes an <code>extern</code> modifier, that method is said to be an <em>external method</em>. External methods are implemented externally, typically using a language other than C#.</p></blockquote>
<p>Unfortunately this means I cannot show you the source to <code>_GetResource</code>, but its likely to be in native C++. The most important aspect of <code>GetManifestResourceStream()</code> is that it returns a pointer to the resource, rather than a instance copy like <code>ResourceManager</code> does. Because of this, the contents of our Bootstrapper.exe resource need not be fully loaded and the magic happens in some external C++ code.</p>
<p>Thanks to such magic under the hood, we can now call our method just as easily as using a <code>ResourceManager</code>.</p>
<pre class="brush: csharp; title: Code; notranslate">namespace ResourceManagerSample
{
    using System;
    using System.IO;
    using System.Linq;
    using System.Reflection;

    internal static class Program
    {
        private static UnmanagedMemoryStream GetResourceStream(String name) {
            Assembly assembly = Assembly.GetExecutingAssembly();

            string[] resources = assembly.GetManifestResourceNames();
            string resource = resources.SingleOrDefault(r =&gt; r.EndsWith(name, StringComparison.CurrentCultureIgnoreCase));

            if (resource == null) {
                throw new System.ArgumentException(&quot;The specified resource does not exist in the assembly manifest.&quot;, &quot;name&quot;);
            }

            return (UnmanagedMemoryStream)assembly.GetManifestResourceStream(resource);
        }

        public static void Main(string[] args) {
            UnmanagedMemoryStream stream = GetResourceStream(&quot;Bootstrapper.exe&quot;);
        }
    }
}</pre>
<p>Except now stepping through the code, you can step through to the end of the method body and see that the <code>UnmanagedMemoryStream</code> is instantiated and to the appropriate size, but our working set memory has not allocated anything extra. How we can allocate memory by reading data from our stream as needed.</p>
<pre class="brush: csharp; title: Code; notranslate">public static void Main(string[] args) {
    UnmanagedMemoryStream stream = GetResourceStream(&quot;Bootstrapper.exe&quot;);

    byte[] buffer = new byte[stream.Length];

    stream.Read(buffer, 0, buffer.Length);
}</pre>
<p>Stepping through the code and stopping at <code>stream.Read(buffer, 0, buffer.Length);</code> just before the statement executes will show that our working set has remained the same. Executing the statement reads the contents into our buffer allocating memory as its read. Only reading from the stream will increase our working set as we need the resource bytes. This is much more efficient than using a <code>ResourceManager</code>, and not hard to implement.</p>
<p>The question now is when to use a <code>ResourceManager</code> with ResX files, and when to use embedded resources. I&#8217;ve not benchmarked one or the other in terms of speed performance, but the whole point was about memory footprint. You should definitely use a <code>ResourceManager</code> if your resources are small, short lived, and you need the ease of being able to access them directly through the <code>ResourceManager</code> class, and by calling <code>GetObject</code> and <code>GetStream</code>. If your resources are very large and your application&#8217;s working set memory might be an issue, you will want to use embedded resources and reflection.</p>
<p>Generally in a project you will use one or the other, and seldom both types of resources, but there isn&#8217;t anything wrong with using both types. It all depends on your requirements, and neither or solves every problem. The trick is picking which one is best for your requirements, just like picking an appropriate programming language to solve a problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/getting-a-stream-to-a-resource-without-copying-the-contents-into-memory/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When is it appropriate to override ToString?</title>
		<link>http://www.danderson.me/2012/05/when-is-it-appropriate-to-override-tostring/</link>
		<comments>http://www.danderson.me/2012/05/when-is-it-appropriate-to-override-tostring/#comments</comments>
		<pubDate>Mon, 07 May 2012 12:07:51 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Guidelines]]></category>
		<category><![CDATA[Override]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[practices]]></category>
		<category><![CDATA[ToString]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=427</guid>
		<description><![CDATA[This question was asked on StackOverflow. Because my answer was upvoted well, I decided include it as a blog post. First, let&#8217;s talk about what ToString actually is. The ToString method lives in System.Object, and because System.Object is the base class for all objects in C#, all objects have the ToString method. Some objects expose [...]]]></description>
			<content:encoded><![CDATA[<p>This question was <a title="Why / when would it be appropriate to override ToString?" href="http://stackoverflow.com/questions/10278049/why-when-would-it-be-appropriate-to-override-tostring" target="_blank">asked on StackOverflow</a>. Because my answer was upvoted well, I decided include it as a blog post.</p>
<p>First, let&#8217;s talk about what <code>ToString</code> actually is. The <code>ToString</code> method lives in <code>System.Object</code>, and because <code>System.Object</code> is the base class for all objects in C#, all objects have the <code>ToString</code> method. Some objects expose <code>ToString</code> overloads that accept parameters like <code>CultureInfo</code>, or formatting options, but for the most part most objects will have the default overload that accepts no parameters.</p>
<p><code>ToString</code> was designed to do one thing: display a representation of an objects state. This is explicitly why it lives in <code>System.Object</code>. That is the only use for <code>ToString</code>, and it should be used. It should not be used to do anything else like change an objects state or apply behaviors.</p>
<p>These are the official guidelines from the .NET Development Series from Microsoft, specifically included in the Framework Design Guidelines book. I highly recommend you buy and read it in full, multiple times.</p>
<p><strong>AVOID</strong> throwing exceptions from <code>ToString</code></p>
<p><strong>CONSIDER</strong> returning a unique string associated with the instance.</p>
<p><strong>CONSIDER</strong> having the output of <code>ToString</code> be a valid input for any parsing methods on this type.</p>
<p><strong>DO</strong> ensure that <code>ToString</code> has no observable side effects.</p>
<p><strong>DO</strong> report security-sensitive information through an override of <code>ToString</code> only after demanding an appropriate permission. If the permission demand fails, return a string excluding security-sensitive information.</p>
<p>The <code>Object.ToString</code> method is intended to be used for general display and debugging purposes. The default implementation simply provides the object type name. The default implementation is not very useful, and it is recommended that the method be overridden.</p>
<p><strong>DO</strong> override <code>ToString</code> whenever an interesting human-readable string can be returned. The default implementation is not very useful, and a custom implementation can almost always provide more value.</p>
<p><strong>DO</strong> prefer a friendly name over a unique but not readable ID.</p>
<p><strong>DO</strong> try to keep the string returned from <code>ToString</code> short. The debugger uses <code>ToString</code> to get a textual representation of an object to be shown to the developer. If the string is longer than the debugger can display, the debugging experience is hindered.</p>
<p><strong>DO</strong> string formatting based on the current thread culture when returning culture-dependent information.</p>
<p><strong>DO</strong> provide overload <code>ToString(string format)</code>, or implement <code>IFormattable</code>, if the string return from <code>ToString</code> is culture-sensitive or there are various ways to format the string. For example, <code>DateTime</code> provides the overload and implements <code>IFormattable</code>.</p>
<p><strong>DO NOT</strong> return an empty string or null from <code>ToString</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/05/when-is-it-appropriate-to-override-tostring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understanding types passed by value or by reference, and what it means to pass a reference type by reference.</title>
		<link>http://www.danderson.me/2012/04/understanding-types-passed-by-value-or-by-reference-and-what-it-means-to-pass-a-reference-type-by-reference/</link>
		<comments>http://www.danderson.me/2012/04/understanding-types-passed-by-value-or-by-reference-and-what-it-means-to-pass-a-reference-type-by-reference/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 10:30:00 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[out]]></category>
		<category><![CDATA[pointer]]></category>
		<category><![CDATA[ref]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[type]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=355</guid>
		<description><![CDATA[Overview. The goal of this article is to explain the mechanisms of passing structures and classes around in code. It will cover areas such as what it means to pass by value, pass by reference, as well as the unique behaviors that structures and classes present. It is recommended that you have at least a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Overview.</strong> The goal of this article is to explain the mechanisms of passing structures and classes around in code. It will cover areas such as what it means to pass by value, pass by reference, as well as the unique behaviors that structures and classes present. It is recommended that you have at least a basic understanding that a structure is a value type, and a class is a reference type, and what each of those means. A brief definition of each is provided in the next section for terminology, but does not go into much detail.</p>
<p><strong>Terminology.</strong> I will try to use these terms precisely and consistantly to prevent as much confusion as possible.</p>
<p>(1) <em>Types. </em>When speaking about structures and references (eg. value types and reference types) both collectively, I will refer to them as <em>types</em>. This will mean that the context applies to both a value type (struct) and a reference type (class).</p>
<p>(2) <em>Value Type. </em>A value type is a struct in C#. Value types directly store their data, and modifying a value type affects only the copy in which you are modifying.</p>
<p>(3) <em>Reference Type. </em>A reference type is a class in C#. Unlike value types, reference types do not directly store their data. Instead, they store a reference to their data, and modifying a reference type modifies the data that it references. Other reference types that reference the same data in memory will also reflect the change.</p>
<p>(4) <em>Pass/Passing by Reference. </em>Refers to passing in a variable as an argument to a method parameter using the ref and out keywords.</p>
<p><strong>Types are passed by value by default.</strong> In C# by default, types are passed into method parameters by value. This means that instead of using a pointer that points to the original storage location in memory, a copy of the type is made in a new storage location.</p>
<p>It is important to understand that value types and reference types have different symantics when passed into a method by value.</p>
<p>(1) <em>Value Type. </em>When a value type is passed by value, a copy of the type is created and any changes to the copy only affect the copy itself; the original type passed in is preserved.</p>
<pre class="brush: csharp; title: Example; notranslate">namespace CSharpDemo
{
    using System.Diagnostics;

    /// &lt;summary&gt;
    /// Simple mutable xy value type
    /// &lt;/summary&gt;
    internal struct Point
    {
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        private int x;
        private int y;

        public int X { get { return x; } set { x = value; } }
        public int Y { get { return y; } set { y = value; } }
    }

    internal class Program
    {
        public static void Main(string[] args) {
            int x = 0;
            int y = 0;

            Point p = new Point(x, y);

            OffsetByOne(p);

            Debug.WriteLine(p.X);
            Debug.WriteLine(p.Y);
        }

        private static void OffsetByOne(Point point) {
            point.X++;
            point.Y++;
        }
    }
}</pre>
<p>In the example above, we are creating an instance of our value type with x and y values of 0 and passing it as an argument to the OffsetByOne(Point) method. Because the default parameter passing mechanism is by value in C#, a copy of our value type is created. The method will increment both X and Y by one, but it is only modifying the copy; the original point we passed in as an argument is preserved. Because of this behavior, printing the contents p.X and p.Y in the Main(string[]) method will both print 0.</p>
<p>(2) <em>Reference Type.</em> A reference type is simply a reference to a underlying type in memory. Unlike a value type, a reference type does not store its own value, rather it is a pointer to the actual value in memory.</p>
<pre class="brush: csharp; title: Example; notranslate">namespace CSharpDemo
{
    using System.Diagnostics;

    /// &lt;summary&gt;
    /// Simple mutable xy reference type
    /// &lt;/summary&gt;
    internal class Point
    {
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        private int x;
        private int y;

        public int X { get { return x; } set { x = value; } }
        public int Y { get { return y; } set { y = value; } }
    }

    internal class Program
    {
        public static void Main(string[] args) {
            int x = 0;
            int y = 0;

            Point p = new Point(x, y);

            OffsetByOne(p);

            Debug.WriteLine(p.X);
            Debug.WriteLine(p.Y);
        }

        private static void OffsetByOne(Point point) {
            point.X++;
            point.Y++;
        }
    }
}</pre>
<p>In the example above note it is the same as the previous example, except that we changed our Point definition from a struct (value type) to a class (reference type). We are creating an instance of our reference type with x and y values of 0 and passing it as an argument to the OffsetByOne(Point) method. </p>
<p>Because the default parameter passing mechanism is by value in C#, a copy of our reference type is created. The method will increment both X and Y by one, and because the copy references the same underlying data in memory as the original type passed in, both references will reflect the change. Because of this behavior, printing the contents p.X and p.Y in the Main(string[]) method will both print 1.</p>
<blockquote><p>This is where a lot of confusion comes from if you don&#8217;t quite understand the symantics of a reference type. A type being a reference type does not mean you are passing by reference, you are still passing by value, and it is important to recognize the difference.</p></blockquote>
<p><strong>Passing types by reference.</strong> Passing types by references can be done two ways. The first method is using the ref keyword, and the second is using the out keyword. It is crucial to know that out is actually identical to ref, but with stronger rules. The out keyword actually gets mapped to the ref keyword in the CLR, but with special metadata for the rules it has.</p>
<p>Both the ref and out keywords do not create new storage locations. Instead, they represent the same storage location as the type given as the argument in the function member. It is important to understand that this is actually a pointer.</p>
<blockquote><p>Because using ref and out means you are actually using a pointer parameter, it is important to know that when passing a reference type by reference, you are actually creating a double pointer, pointer to pointer, or double indirection. This is because a reference type itself is a pointer to a storage location in memory. It is highly recommended to have some knowledge and understanding of how pointers work before deciding whether passing a type, especially a reference type by reference is actually necessary.</p></blockquote>
<p>(1) <em>ref</em>. A reference type must be definitely assigned before it can be passed as a reference parameter. Because of this rule, a reference parameter is always considered initially assigned within a function.</p>
<pre class="brush: csharp; title: Example; notranslate">namespace CSharpDemo
{
    using System.Diagnostics;

    /// &lt;summary&gt;
    /// Simple mutable xy value type
    /// &lt;/summary&gt;
    internal struct Point
    {
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        private int x;
        private int y;

        public int X { get { return x; } set { x = value; } }
        public int Y { get { return y; } set { y = value; } }
    }

    internal class Program
    {
        public static void Main(string[] args) {
            int x = 0;
            int y = 0;

            Point p = new Point(x, y);

            OffsetByOne(ref p);

            Debug.WriteLine(p.X);
            Debug.WriteLine(p.Y);
        }

        private static void OffsetByOne(ref Point point) {
            point.X++;
            point.Y++;
        }
    }
}</pre>
<p>Make note that in the example above we are working with a value type again, and that there are two key changes. The first change is that we added a reference parameter to our OffsetByOne(Point) method, which changes the signature to OffsetByOne(ref Point). The second change is our calling syntax has changed by also adding the ref keyword. This convention is that of passing a type by reference using the ref keyword.</p>
<p>For a value type, passing by reference means that you get reference type symantics. By passing our value type by reference, OffsetByOne(ref Point) will actually modify the value of the original type passed in. The behavior of this is that printing the contents of p.X and p.Y in Main(string[]) will now both print the value of 1.</p>
<p>Now because passing a reference type by reference means using a double pointer, pointer to pointer, or double indirection, I will cover passing a reference type by reference later in the article.</p>
<p>(2) <em>out</em>. As I stated earlier, the rules for out are much stronger. A type does not need to be definitely assigned before it can be passed as an argument.</p>
<blockquote><p>It&#8217;s important to note here that if you do assign your type before passing it as an argument using the out keyword, don&#8217;t expect your value to be retained.</p></blockquote>
<p>I urge the point above because when using the out keyword, it is required that the type passed in as an argument be definitely assigned before the method returns normally. This means that no matter what, the type that you passed in will be assigned a new value, overwriting any old value that was there.</p>
<p>Parameters passed in via out, are actually considered output parameters. These should be treated as additional return values, so treat it with return type symantics.</p>
<pre class="brush: csharp; title: Example; notranslate">namespace CSharpDemo
{
    using System.Diagnostics;

    /// &lt;summary&gt;
    /// Simple mutable xy value type
    /// &lt;/summary&gt;
    internal struct Point
    {
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        private int x;
        private int y;

        public int X { get { return x; } set { x = value; } }
        public int Y { get { return y; } set { y = value; } }
    }

    internal class Program
    {
        public static void Main(string[] args) {
            int x = 0;
            int y = 0;

            Point p = new Point(x, y);

            OffsetByOne(out p);

            Debug.WriteLine(p.X);
            Debug.WriteLine(p.Y);
        }

        private static void OffsetByOne(out Point point) {
            int x = 1;
            int y = 1;

            point = new Point(x, y);

            point.X++;
            point.Y++;
        }
    }
}</pre>
<p>The only difference between this example and the ref example, is that we are using the out keyword and I have updated the OffsetByOne(out Point) method body. Note that because we must definitely assign the parameter named point before the method returns, we are assigning it a new Point with a XY values of 1. Because when passing a value type by reference we get reference type symantics, printing the value of our type in Main(string[]) will yield XY values of 2.</p>
<blockquote><p>Again, out and ref are the same, but out should be treated as an extra return value. With ref you can always expect your value to either be changed, or unchanged, but with out you should expect a completely new value each time just as if you were consuming a normal return value from a method.</p></blockquote>
<p><strong>Passing a reference type by reference.</strong> Hopefully by the time you get to this part you already have an idea of what I&#8217;m about to say. It&#8217;s not complicated. The importance here is that you simply understand the symantics of a reference type itself, and that passing a reference type <em>does not automatically mean passing by reference</em>.</p>
<p>At any rate, I hope you enjoyed the article and that it provided some insight.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/04/understanding-types-passed-by-value-or-by-reference-and-what-it-means-to-pass-a-reference-type-by-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FaultException`1 was unhandled when trying to deserialize parameter http://tempuri.org/:request</title>
		<link>http://www.danderson.me/2012/04/faultexception1-was-unhandled-when-trying-to-deserialize-parameter-httptempuri-orgrequest/</link>
		<comments>http://www.danderson.me/2012/04/faultexception1-was-unhandled-when-trying-to-deserialize-parameter-httptempuri-orgrequest/#comments</comments>
		<pubDate>Mon, 23 Apr 2012 23:37:41 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[exception]]></category>
		<category><![CDATA[immutable]]></category>
		<category><![CDATA[serialization]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=351</guid>
		<description><![CDATA[I just finished my activation system which is just a WCF service, finished all the unit tests and ensured they passed and met requirements. Now its time to make a test client, so I load up Visual Studio and start a simple Console Application with the service reference to IIS Express, and boom! Failure. The [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished my activation system which is just a WCF service, finished all the unit tests and ensured they passed and met requirements. Now its time to make a test client, so I load up Visual Studio and start a simple Console Application with the service reference to IIS Express, and boom! Failure. The WCF code that consumes the service is rather simple.</p>
<pre class="brush: csharp; highlight: [10]; title: Code; notranslate">static void Main(string[] args) {
    ActivationServiceClient client = new ActivationServiceClient();

    ActivationRequest request = new ActivationRequest();
    request.DateCreated = DateTime.Now;
    request.MachineName = Environment.MachineName;
    request.ProductCode = Guid.NewGuid();
    request.ProductKey = &quot;ABCDEFGHIJKLMNPQRSTUVWXYZ&quot;;

    ActivationResponse response = client.Activate(request);

    byte[] license = response.License;
    string licenseHash = response.LicenseHash;
    ActivationResult result = response.Result;
}</pre>
<p>I highlighted line 10, because that&#8217;s where the failure is. Here&#8217;s the full exception.</p>
<blockquote><p><strong>FaultException`1 was unhandled<br />
</strong>There was an error while trying to deserialize parameter <a href="http://tempuri.org/:request">http://tempuri.org/:request</a>. Please see InnerException for more details.</p></blockquote>
<p>I do the obvious and check the inner exception, but there is none. However I noticed there was a Details property with some extra data that read the following.</p>
<blockquote><p>{An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:<br />
System.Runtime.Serialization.InvalidDataContractException: There was an error while trying to deserialize parameter http://tempuri.org/:request.  Please see InnerException for more details. &#8212;-> System.Runtime.Serialization.InvalidDataContractException: No set method for property &#8216;ProductKey&#8217; in type &#8216;DCOMProductions.Activation.ActivationRequest&#8217;. The class cannot be deserialized.</p></blockquote>
<p>In short, it says that there is no set method for property `ProductKey`. This is true because the ActivationRequest structure is immutable by design. I designed the class so that the properties are initialized through constructor parameters, and the class itself is immutable. However, you will notice that on the client that consumes the service, the service reference created a type that is not immutable and has no constructor parameters. In addition, the type created by the service reference is mutable.</p>
<p>After thinking about the problem and doing some research I found that WCF requires two-way serialization by default. This means that by applying [DataMember] attribute on a property, it would need to have both the get and set accessors. While its not recommended to mark member fields as a DataMember, in this scenario it is the solution. Let&#8217;s take a look at some code.</p>
<pre class="brush: csharp; title: DataMember Property; notranslate">private string name;
[DataMember]
public string Name {
    get {
        return name;
    }
}</pre>
<pre class="brush: csharp; title: DataMember Member Field; notranslate">[DataMember]
private string name;

public string Name {
    get {
        return name;
    }
}</pre>
<p>The first code example would cause the WCF service to fail because it does not allow for two-way serialization, however the second would be fine since we are decorating the backing field as the DataMember instead of the read-only property. There&#8217;s really not much else to say here, but there are tradeoffs for one good practice over another. In this case we are trading the good practice of decorating properties as DataMembers for the good practice of immutable structures.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/04/faultexception1-was-unhandled-when-trying-to-deserialize-parameter-httptempuri-orgrequest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cannot obtain Metadata from WCF service when using Microsoft WCF Test Client.</title>
		<link>http://www.danderson.me/2012/04/cannot-obtain-metadata-from-wcf-service-when-using-microsoft-wcf-test-client/</link>
		<comments>http://www.danderson.me/2012/04/cannot-obtain-metadata-from-wcf-service-when-using-microsoft-wcf-test-client/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 04:43:47 +0000</pubDate>
		<dc:creator>David Anderson</dc:creator>
				<category><![CDATA[C#/.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Configuration]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[Mex]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.dcomproductions.com/blog/?p=344</guid>
		<description><![CDATA[I just finished writing the technical whitepapers for my product activation service, so I started the actual implementation using WCF services. All was good, added the usual WCF Service Application project, ran a quick F5, and swapped out all the default services with my own. Then I ran a F5 debug, and wait what? The [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished writing the technical whitepapers for my product activation service, so I started the actual implementation using WCF services. All was good, added the usual WCF Service Application project, ran a quick F5, and swapped out all the default services with my own. Then I ran a F5 debug, and wait what? The WCF Test Client could not run my service.</p>
<blockquote><p>Microsoft WCF Test Client</p>
<p>Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.</p></blockquote>
<p>I vigorously checked the configuration, because I often write my by hand instead of using the WCF tool, and everything checked out. Here is what my configuration looked like, which is a valid configuration.</p>
<pre class="brush: xml; title: App.config; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
&lt;configuration&gt;
    &lt;system.web&gt;
        &lt;compilation debug=&quot;true&quot; /&gt;
    &lt;/system.web&gt;
    &lt;system.serviceModel&gt;
        &lt;services&gt;
            &lt;service name=&quot;DCOMProductions.Activation.ActivationService&quot;&gt;
                &lt;endpoint binding=&quot;wsHttpBinding&quot; contract=&quot;DCOMProductions.Activation.IActivationService&quot;&gt;
                    &lt;identity&gt;
                        &lt;dns value=&quot;localhost&quot; /&gt;
                    &lt;/identity&gt;
                &lt;/endpoint&gt;
                &lt;endpoint address=&quot;mex&quot; binding=&quot;mexHttpBinding&quot; contract=&quot;IMetadataExchange&quot; /&gt;
                &lt;host&gt;
                    &lt;baseAddresses&gt;
                        &lt;add baseAddress=&quot;http://localhost:8732/Design_Time_Addresses/DCOMProductions.Activation/ActivationService/&quot; /&gt;
                    &lt;/baseAddresses&gt;
                &lt;/host&gt;
            &lt;/service&gt;
        &lt;/services&gt;
        &lt;behaviors&gt;
            &lt;serviceBehaviors&gt;
                &lt;behavior&gt;
                    &lt;serviceMetadata httpGetEnabled=&quot;true&quot; /&gt;
                    &lt;serviceDebug includeExceptionDetailInFaults=&quot;true&quot; /&gt;
                &lt;/behavior&gt;
            &lt;/serviceBehaviors&gt;
        &lt;/behaviors&gt;
    &lt;/system.serviceModel&gt;
&lt;/configuration&gt;</pre>
<p>What the heck? Because everything I could think of is valid, I then pointed my finger at something being wrong with my code. Something has to be causing the test client to fail. I tested this theory by navigating to the service address in Internet Explorer, which revealed that it was encountering a server error, which proved my theory.</p>
<p>Taking a look at my code, I quickly realized that I had some Composite Types in my service. One of the composite types is an Enum.</p>
<pre class="brush: csharp; highlight: [21,23]; title: ActivationResult.cs; notranslate">//-----------------------------------------------------------------------------
// &lt;copyright file=&quot;ActivationResult.cs&quot; company=&quot;DCOM Productions&quot;&gt;
//     Copyright (c) DCOM Productions.  All rights reserved.
// &lt;/copyright&gt;
//-----------------------------------------------------------------------------

namespace DCOMProductions.Activation
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Runtime.Serialization;

    /// &lt;summary&gt;
    /// The result of the activation request
    /// &lt;/summary&gt;
    [DataContract]
    public enum ActivationResult
    {
        [DataMember]
        None,
        [DataMember]
        Passed
    }
}</pre>
<p>If you notice, I have highlighted lines 21 and 23. The problem is that enumeration fields should use the EnumMemberAttribute, and not DataMemberAttribute. I changed the attributes, ran a F5 debug and low-and-behold, the service worked great.</p>
<p>If you find yourself pulling your hair out over WCF configuration problems, check your code too. It may just be something simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danderson.me/2012/04/cannot-obtain-metadata-from-wcf-service-when-using-microsoft-wcf-test-client/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

