<?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>nerdcore.com.br</title>
	<atom:link href="http://www.nerdcore.com.br/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nerdcore.com.br/blog</link>
	<description>nerd &#039;n&#039; proud</description>
	<lastBuildDate>Mon, 23 Jan 2012 07:54:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Microsoft Certified Technology Specialist</title>
		<link>http://www.nerdcore.com.br/blog/2010/12/mcts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=mcts</link>
		<comments>http://www.nerdcore.com.br/blog/2010/12/mcts/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 10:59:27 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[profissional]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[mcts]]></category>
		<category><![CDATA[Windows Presentation Foundation]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=255</guid>
		<description><![CDATA[On December 10th I got my first Microsoft certification. I&#8217;m now a Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Presentation Foundation Applications. I got 957/1,000, so I&#8217;m proud about myself.]]></description>
			<content:encoded><![CDATA[<p>On December 10th I got my first Microsoft certification. I&#8217;m now a Microsoft Certified Technology Specialist: .NET Framework 3.5, Windows Presentation Foundation Applications. I got 957/1,000, so I&#8217;m proud about myself. <img src='http://www.nerdcore.com.br/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p style="text-align: center;"><a href="http://www.nerdcore.com.br/blog/wp-content/uploads/2010/12/MCTSrgb_1098.png"><img class="aligncenter" title="MCTS" src="http://www.nerdcore.com.br/blog/wp-content/uploads/2010/12/MCTSrgb_1098.png" alt="Microsoft Certified Technology Specialist" width="498" height="80" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/12/mcts/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Opening files closes VS2008</title>
		<link>http://www.nerdcore.com.br/blog/2010/08/opening-files-close-vs2008/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=opening-files-close-vs2008</link>
		<comments>http://www.nerdcore.com.br/blog/2010/08/opening-files-close-vs2008/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 11:33:51 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[visual studio 2008]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=249</guid>
		<description><![CDATA[Once in a while I happen to have a project that simply closes when a file such as .resx or .xaml is openened in Visual Studio 2008 &#8211; even when there is nothing wrong with the files themselves. When that happens, errors are logged to the Event Viewer, but they are not that helpful &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while I happen to have a project that simply closes when a file such as .resx or .xaml is openened in Visual Studio 2008 &#8211; even when there is nothing wrong with the files themselves.</p>
<p>When that happens, errors are logged to the Event Viewer, but they are not that helpful &#8211; for a change.</p>
<p>To avoid that error, there is a couple of ways. First of all, delete the .suo file in your solution folder. Deleting that file will do no harm to your solutions, as it only stores user-specific information, such as what are your opened files, which directories in Solution Explorer are collapsed or not, etc.</p>
<p>That usually works. However, not always, specially with .xaml files. If VS2008 insists in closing after deleting .suo, next time you open the .xaml file, simply press ESC repetitively, the way maniacs do. That will avoid the design view to be loaded &#8211; which apparently breaks VS2008. If you are successful in not seeing VS2008 to close again, you can close your file and re-open it. <strong>Hopefully</strong>.</p>
<p>What if Visual Studio still closes? Good luck, my friend.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/08/opening-files-close-vs2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>String.Format() on XAML for WPF</title>
		<link>http://www.nerdcore.com.br/blog/2010/08/string-format-on-xaml-for-wpf/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=string-format-on-xaml-for-wpf</link>
		<comments>http://www.nerdcore.com.br/blog/2010/08/string-format-on-xaml-for-wpf/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 18:06:35 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[binding]]></category>
		<category><![CDATA[mvvm]]></category>
		<category><![CDATA[wpf]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=217</guid>
		<description><![CDATA[Just found out some nice tricks on WPF, so here are some quick hints about using String.Format() with multiple parameters on XAML for WPF (and possibly Silverlight). Say that you have a Phone class that contains three properties: CountryCode, AreaCode and Number. The DataContext for your Window contains a property of type Phone, and you want [...]]]></description>
			<content:encoded><![CDATA[<p>Just found out some nice tricks on WPF, so here are some quick hints about using String.Format() with multiple parameters on XAML for WPF (and possibly Silverlight).</p>
<p>Say that you have a <em>Phone </em>class that contains three properties: <em>CountryCode</em>, <em>AreaCode </em>and <em>Number</em>. The <em>DataContext</em> for your Window contains a property of type <em>Phone</em>, and you want to print that object information in a pre-formatted way defined at the XAML file. The desired format is something like <em>+1 55 55555555</em> (plus sign, followed by <em>CountryCode</em>, followed by a space, followed by <em>AreaCode</em>, followed by a space, followed by <em>Number</em>).</p>
<p>So instead of creating a property to hold the pre-formatted string at your class side, you just want to define it at XAML level.</p>
<p>Take the code below as an example:</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">&lt;TextBlock&gt;
	&lt;TextBlock.Text&gt;
		&lt;MultiBinding StringFormat=&quot;+{0} {1} {2}&quot;&gt;
			&lt;Binding Path=&quot;Phone.CountryCode&quot; /&gt;
			&lt;Binding Path=&quot;Phone.AreaCode&quot; /&gt;
			&lt;Binding Path=&quot;Phone.Number&quot; /&gt;
		&lt;/MultiBinding&gt;
	&lt;/TextBlock.Text&gt;
&lt;/TextBlock&gt;</pre>
<p>That will just do the trick for you!</p>
<p>However, we have some considerations to pay attention at. First of all:</p>
<pre class="brush: xml; light: true; title: ; notranslate">&lt;MultiBinding StringFormat=&quot;+{0} {1} {2}&quot;&gt;</pre>
<p>That line just works because of that trailing plus sign. If you were to use no plus sign (or any other prefixing string) at all and just display <em>CountryCode</em> directly, then you need a small tweak:</p>
<pre class="brush: xml; light: true; title: ; notranslate">&lt;MultiBinding StringFormat=&quot;{}{0} {1} {2}&quot;&gt;</pre>
<p>That&#8217;s the <strong>{}</strong> just before <strong>{0}</strong> parameter.</p>
<p>Furthermore, there are some nice attributes to add to the <em>Binding</em> element. For instance, if the value of your DataContext <em>Phone</em> object can&#8217;t be retrieved in design-time, you might see <em>{DependencyProperty.UnsetValue}</em> displayed on your design screen. <em>TargetNullValue</em> and <em>FallbackValue</em> can be added to fix that.</p>
<pre class="brush: xml; light: true; title: ; wrap-lines: false; notranslate">&lt;TextBlock&gt;
	&lt;TextBlock.Text&gt;
		&lt;MultiBinding StringFormat=&quot;+{0} {1} {2}&quot;&gt;
			&lt;Binding Path=&quot;Phone.CountryCode&quot; TargetNullValue=&quot;--&quot; FallbackValue=&quot;??&quot; /&gt;
			&lt;Binding Path=&quot;Phone.AreaCode&quot; TargetNullValue=&quot;--&quot; FallbackValue=&quot;??&quot; /&gt;
			&lt;Binding Path=&quot;Phone.Number&quot; TargetNullValue=&quot;--------&quot; FallbackValue=&quot;????????&quot; /&gt;
		&lt;/MultiBinding&gt;
	&lt;/TextBlock.Text&gt;
&lt;/TextBlock&gt;</pre>
<p>The first one is the substitution for null values, while the value of the second one is returned when no value can be found (such as when the bound property is not initialized in design-time). Just take care as that works on runtime as well!</p>
<p>Just some tricks particularly interesting during MVVM development. I hope it can be of some help!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/08/string-format-on-xaml-for-wpf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Metaphor of a webdeveloper&#8217;s life</title>
		<link>http://www.nerdcore.com.br/blog/2010/03/metaphor-of-a-webdevelopers-life/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=metaphor-of-a-webdevelopers-life</link>
		<comments>http://www.nerdcore.com.br/blog/2010/03/metaphor-of-a-webdevelopers-life/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:51:37 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[humour]]></category>
		<category><![CDATA[ska]]></category>
		<category><![CDATA[The Aquabats]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=211</guid>
		<description><![CDATA[I was just listening to The Aquabats &#8211; The Baker and I guess I paid attention to the lyrics for the first time. It just tells the story of every webdeveloper and their conflict with webdesigners: I am the Baker I bake the cake You&#8217;re the decorator and you decorate You take the credit While [...]]]></description>
			<content:encoded><![CDATA[<p>I was just listening to <a title="The Aquabats - The Baker" href="http://www.youtube.com/watch?v=77O6iqThpRQ" target="_blank">The Aquabats &#8211; The Baker</a> and I guess I paid attention to the lyrics for the first time. It just tells the story of every webdeveloper and their conflict with webdesigners:</p>
<blockquote>
<div id="_mcePaste">I am the Baker</div>
<div id="_mcePaste">I bake the cake</div>
<div id="_mcePaste">You&#8217;re the decorator and you decorate</div>
<div id="_mcePaste">You take the credit</div>
<div id="_mcePaste">While I slave away</div>
<div id="_mcePaste">I mixed, I made, I baked!</div>
</blockquote>
<p>You can check the lyrics <a title="Lyrics for The Aquabats - The Baker" href="http://www.songmeanings.net/songs/view/39138/" target="_blank">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/03/metaphor-of-a-webdevelopers-life/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The philosophy of technical restrictions: why value comparison is not available in .NET?</title>
		<link>http://www.nerdcore.com.br/blog/2010/01/the-philosophy-of-technical-restrictions-why-value-comparison-is-not-available-in-net/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-philosophy-of-technical-restrictions-why-value-comparison-is-not-available-in-net</link>
		<comments>http://www.nerdcore.com.br/blog/2010/01/the-philosophy-of-technical-restrictions-why-value-comparison-is-not-available-in-net/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:34:11 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[object orientation]]></category>
		<category><![CDATA[philosophy]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=193</guid>
		<description><![CDATA[Or: Unavailability of value comparison of objects in .NET, a technical or philosophical restriction? I was working on unit tests and then a question came to me &#8211; why comparing objects by value is not provided out-of-the-box by the .NET Framework? We all (should) know that by default, comparing objects leads to a reference comparison, [...]]]></description>
			<content:encoded><![CDATA[<p>Or: <em>Unavailability of value comparison of objects in .NET, a technical or philosophical restriction?</em></p>
<p>I was working on unit tests and then a question came to me &#8211; why comparing objects by value is not provided out-of-the-box by the .NET Framework? We all (should) know that by default, comparing objects leads to a <strong>reference</strong> comparison, unless of course you override <em>Equals()</em> or implement <em>operator ==</em> on your class.</p>
<p>But what if I want to compare two objects from a class provided by the Framework? That would be quite handy specially for unit tests. While we have <a title="Object.Equals Method" href="http://msdn.microsoft.com/en-us/library/system.object.equals.aspx" target="_blank">System.Object.Equals()</a> and <a title="Object.ReferenceEquals Method" href="http://msdn.microsoft.com/en-us/library/system.object.referenceequals.aspx" target="_blank">System.Object.ReferenceEquals()</a> working the very same way &#8211; reference comparison &#8211; we don&#8217;t find something like <em>System.Object.ValueEquals()</em>.</p>
<p>Then I started having a discussion with a friend and colleague of mine the reasons for such functionality not existing in .NET.</p>
<p>Although I agree that the default option should be reference comparison, I don&#8217;t see any technical limitations for not having that implemented &#8211; Reflection could be the way to do it, going recursively down each property and checking if their values are equal.</p>
<p>So why not? Is it something related to the theory of object orientation or was it a mere technical decision?</p>
<p>Let&#8217;s take one of the classical examples of OO lessons: a <em>Car</em> class. In a Car, you have properties such as Color, Model, Category, etc. In real life, when two cars come out of production line, while you can&#8217;t say they are the <strong>same car</strong>, one would have no problem identifying they were built by the same method. Just compare each of their properties and you will end up <strong>knowing</strong> they are not the same car, but they share the same properties and were built the same way. They don&#8217;t share a reference equality, but <strong>value equality</strong>.</p>
<p>As far as I am concerned, OO does not provide a specific way or method to apply the property-by-property comparison, but there isn&#8217;t a prohibition on doing that as well.</p>
<p>However, providing such functionality could be an expensive trade-off, since gigantic objects with collections with millions of items could be compared. It would be possible, but sometimes <strong>not practical</strong>. But then not providing that for the developer&#8217;s discretion, or at least providing ways to ensure it could be safely used? Doesn&#8217;t seems right to me.</p>
<p>From my point of view, such functionality could be very useful and there is no true restriction that should be applied for having something like that provided by the Framework. As I said, my opinion is that not providing it is a technical decision, and not a philosophical restriction imposed by OO theory.</p>
<p>What do you think? I&#8217;d be glad to listen to other opinions!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/01/the-philosophy-of-technical-restrictions-why-value-comparison-is-not-available-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validation error on compiling unused Activity with custom ActivityValidator</title>
		<link>http://www.nerdcore.com.br/blog/2010/01/validation-error-on-compiling-unused-activity-with-custom-activityvalidator/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validation-error-on-compiling-unused-activity-with-custom-activityvalidator</link>
		<comments>http://www.nerdcore.com.br/blog/2010/01/validation-error-on-compiling-unused-activity-with-custom-activityvalidator/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 19:40:51 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[ActivityValidator]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[custom activity]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[Windows Workflow Foundation]]></category>
		<category><![CDATA[workflow]]></category>
		<category><![CDATA[WWF]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=178</guid>
		<description><![CDATA[Although I&#8217;ve worked with WWF (Windows Workflow Foundation) during all 2009, I haven&#8217;t posted anything about the technology yet, so I thought it was maybe the time to do it. I&#8217;ll start with one of the bases of the implementation of custom ActivityValidator classes. Despite being simple, that is an error that strikes new workflow [...]]]></description>
			<content:encoded><![CDATA[<p>Although I&#8217;ve worked with WWF (Windows Workflow Foundation) during all 2009, I haven&#8217;t posted anything about the technology yet, so I thought it was maybe the time to do it. I&#8217;ll start with one of the bases of the implementation of custom <a href="http://msdn.microsoft.com/en-us/library/system.workflow.componentmodel.compiler.activityvalidator.aspx" target="_blank">ActivityValidator</a> classes. Despite being simple, that is an error that strikes new workflow developers quite often.</p>
<p>When creating a custom <em>ActivityValidator</em>, you might receive a compilation error from the newly created validator, even when the custom <em>Activity</em> it is targeted against is not in use yet.</p>
<p>But how come? Let&#8217;s take a look at the example below:</p>
<pre class="c-sharp" name="code" nowrap>[ActivityValidator(typeof(MyCustomValidator))]
public partial class MyCustomActivity : Activity
{
    public static DependencyProperty PriceProperty = DependencyProperty.Register("Price", typeof(float), typeof(MyCustomActivity));

    [DescriptionAttribute("Price")]
    [CategoryAttribute("Price Category")]
    [BrowsableAttribute(true)]
    [DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Visible)]
    public float Price
    {
        get
        {
            return ((float)(base.GetValue(MyCustomActivity.PriceProperty)));
        }
        set
        {
            base.SetValue(MyCustomActivity.PriceProperty, value);
        }
    }

	public MyCustomActivity()
	{
		InitializeComponent();
	}
}

public class MyCustomValidator : ActivityValidator
{
    public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
    {
        MyCustomActivity myCustomActivity = obj as MyCustomActivity;
        ValidationErrorCollection errors = base.Validate(manager, obj);

        if (myCustomActivity == null)
        {
            throw new ArgumentException("MyCustomValidator can only be used to validate MyCustomActivity instances.", "obj");
        }

        if (myCustomActivity.Price <= 0)
        {
            errors.Add(new ValidationError("'Price' must be greater than zero.", 1));
        }

        return errors;
    }
}</pre>
<p>In the example above, when you build the project you will receive an error such as</p>
<blockquote><p>Error<span> </span>1<span> </span>Activity 'MyCustomActivity' validation failed: 'Price' must be greater than zero.</p></blockquote>
<p>Well, that is not nice. You are not even using <em>MyCustomActivity</em> yet!</p>
<p>The reason for that is simple: validators are run during runtime, but <strong>also</strong> during build time! To avoid the error, we simply check if the custom activity is in use. How? Take a peak:</p>
<pre class="c-sharp" name="code" nowrap>public class MyCustomValidator : ActivityValidator
{
    public override ValidationErrorCollection Validate(ValidationManager manager, object obj)
    {
        MyCustomActivity myCustomActivity = obj as MyCustomActivity;
        ValidationErrorCollection errors = base.Validate(manager, obj);

        if (myCustomActivity == null)
        {
            throw new ArgumentException("MyCustomValidator can only be used to validate MyCustomActivity instances.", "obj");
        }

        if (myCustomActivity.Parent != null)
        {
            if (myCustomActivity.Price <= 0)
            {
                errors.Add(new ValidationError("'Price' must be greater than zero.", 1));
            }
        }

        return errors;
    }
}</pre>
<p>As you can see, all we did was checking if the activity parent is not null (line 13).</p>
<p>Try to build now, no error will be triggered. Then drop <em>MyCustomActivity</em> to a workflow, don't fill in <em>Price</em> and build again. The error is now there, correctly returned!</p>
<p>Well, that was it... No black magic but surely resourceful! I hope it helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2010/01/validation-error-on-compiling-unused-activity-with-custom-activityvalidator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nerd &#8216;n&#8217; proud 2009</title>
		<link>http://www.nerdcore.com.br/blog/2009/05/nerd-n-proud-2009/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=nerd-n-proud-2009</link>
		<comments>http://www.nerdcore.com.br/blog/2009/05/nerd-n-proud-2009/#comments</comments>
		<pubDate>Mon, 25 May 2009 13:06:54 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[nerds]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=171</guid>
		<description><![CDATA[Nerd Pride Day. I'm nerd 'n' proud.]]></description>
			<content:encoded><![CDATA[<p>You are here. You are a nerd. And you are proud of that.<br />
Be happy, today is our day! Happy <a target="_blank" title="Nerd Pride Day" mce_href="http://en.wikipedia.org/wiki/Nerd_Pride_Day" href="http://en.wikipedia.org/wiki/Nerd_Pride_Day">Nerd Pride Day</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2009/05/nerd-n-proud-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Oh no, not AG_E_PARSER_UNKNOWN_TYPE!</title>
		<link>http://www.nerdcore.com.br/blog/2009/04/oh-no-not-ag_e_parser_unknown_type/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=oh-no-not-ag_e_parser_unknown_type</link>
		<comments>http://www.nerdcore.com.br/blog/2009/04/oh-no-not-ag_e_parser_unknown_type/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 20:15:08 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[AG_E_PARSER_UNKNOWN_TYPE]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[user controls]]></category>
		<category><![CDATA[UserControl]]></category>
		<category><![CDATA[xaml]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=132</guid>
		<description><![CDATA[So you found yourself challenging him. Find here some tips on identifying a possible reason for the misterious AG_E_PARSER_UNKNOWN_TYPE error on Silverlight 2 xaml files.]]></description>
			<content:encoded><![CDATA[<p>You are coding an UserControl for your Silverlight 2 application that might change the world. You are almost done with it, already told all the guys that the first round is on you. You are thrilled about your fabulous coding skills.</p>
<p>And then you find him. An horrendous, terrible, dreadful enemy. His name: <em>AG_E_PARSER_UNKNOWN_TYPE</em>.</p>
<p><a title="Hopduvel" href="http://flickr.com/photos/27703725@N00/2908763546" target="_blank"><img style="margin: 4px; float: right;" title="You don't want to cross his path." src="http://farm4.static.flickr.com/3194/2908763546_9ebe321b51_m.jpg" alt="You don't want to cross his path." width="191" height="240" /></a></p>
<p>You start looking for reasons of such an error, but all you find is despair. No hints, no clues, you start loosing your temper &#8211; and possibly your hair. You curse the framework for not supplying you with enough information: just a plain <em>AG_E_PARSER_UNKNOWN_TYPE</em> on your xaml file. Googling does not help you much, as few have faced that horrible vilain.</p>
<p>Fear not, friend, as I have found him myself, and I am going to share the secrets of some of his weak spots. Explore them, and I hope you defeat him the way I did.</p>
<p>Jokes apart, that was an error that took me a while to figure it out. Everything happened when I was creating user controls that were related to each other by their parent class. And impressively I run into two different situations in the same task that lead me to <em>AG_E_PARSER_UNKNOWN_TYPE</em>.</p>
<p>My solution was structured as follows:</p>
<pre class="c-sharp" name="code">using System;
using System.ComponentModel;

namespace MySolution
{
    public abstract class MyBaseClass : UserControl
    {
    }

    public partial class MyClass1 : MyBaseClass
    {
    }

    public partial class MyClass2 : MyBaseClass
    {
    }
}</pre>
<p>First error in the intended code above: the <em>MyBaseClass</em> derivating from UserControl can&#8217;t be declared abstract. I know, it is a pain in case you want to create an abstract method within &#8211; you won&#8217;t be able to do that at all. Try a workaround like creating virtual methods throwing a <em>NotImplementedException</em>, and then overriding it with the real implementation.</p>
<p>The other situation I found that error in was related to listeners and the user control constructor. I&#8217;m not entirely sure why that happens, but if you register for a listener on the constructor class (or call any method registering it from the constructor) of your user control, you might have a chance to encounter the might evil <em>AG_E_PARSER_UNKNOWN_ERROR</em> is.</p>
<p>Also, a collegue pointed out for me a <a title="Silverlight Erro Codes Explained" href="http://exdream.no-ip.info/blog/2007/07/20/SilverlightErrorCodesExplained.aspx" target="_blank">blog post</a> with some explanations to <em>AG_E_PARSER_UNKNOWN_ERROR</em> and other Silverlight hell minions alike. Despite being related to Silverlight 1.1 alpha, I found the list to be trully helpful. I wish I had found that one before, the struggle would be much smaller!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2009/04/oh-no-not-ag_e_parser_unknown_type/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Wait messages and asynchronous calls in Silverlight 2</title>
		<link>http://www.nerdcore.com.br/blog/2009/02/wait-messages-and-asynchronous-calls-in-silverlight-2/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wait-messages-and-asynchronous-calls-in-silverlight-2</link>
		<comments>http://www.nerdcore.com.br/blog/2009/02/wait-messages-and-asynchronous-calls-in-silverlight-2/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 13:08:01 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[silverlight]]></category>
		<category><![CDATA[threading]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=41</guid>
		<description><![CDATA[Today I had a nice learning experience on how to handle "please wait" screens and asynchronous calls on Silverlight 2.

Say that you want to present a message to your user while he waits an asynchronous call to be completed. However, given the nature of the call, you can't control how long it will take to complete, and thus that message may be just a quick blink in the screen. But what if you still want that message to be readable, even when the call answers almost instantaneously?]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-thumbnail wp-image-28" style="float: right; border: 0px; margin: 5px;" title="Silverlight" src="http://www.nerdcore.com.br/blog/wp-content/uploads/2009/02/silverlightlogo100.jpg" alt="Silverlight" width="100" height="110" />Today I had a nice learning experience on how to handle &#8220;please wait&#8221; screens and asynchronous calls on Silverlight 2.</p>
<p>Say that you want to present a message to your user while he waits an asynchronous call to be completed. However, given the nature of the call, you can&#8217;t control how long it will take to complete, and thus that message may be just a quick blink in the screen. But what if you still want that message to be readable, even when the call answers almost instantaneously?</p>
<p>Using <em>System.Threading.Thread.Sleep()</em> is not a good option, since it will hold the <span style="text-decoration: underline;">current</span> thread &#8211; that is, the UI thread. And the user will be probably pissed off for having his browser frozen by the application.</p>
<p>The solution: <em>BackgroundWorker</em> and <em>Dispatcher</em> classes.</p>
<p><em>System.ComponentModel.BackgroundWorker</em> (<a title="BackgroundWorker Class (System.ComponentModel)" href="http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx" target="_blank">MSDN link</a>) is a class that allows instructions to be run on a dedicated thread, with support to cancellation and progress reporting, while <em>Dispatcher</em> (<a href="http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher(VS.95).aspx" target="_blank">MSDN link</a>) is a handy property from the <em>UserControl</em> class (the one used as a base class to Silverlight pages) that gives us access to the UI thread.</p>
<p>Let&#8217;s see a simple example on how to implement the proposed solution.</p>
<pre name="code" class="c-sharp">using System;
using System.ComponentModel;
using System.Threading;

public class Page : UserControl
{
    // Bogus is any given class with an asynchronous call
    private Bogus bogus;
    private BackgroundWorker bgWorker;

    public Page()
    {
        InitializeComponent();

        // Creates the BackgroundWorker and says it supports cancellation
        bgWorker = new BackgroundWorker();
        bgWorker.WorkerSupportsCancellation = true;

        // Registers the listener
        bgWorker.DoWork += new DoWorkEventHandler(bgWorker_DoWork);

        // Instantiate the class that runs the asynchronous call
        bogus = new Bogus();
    }

    #region Button handlers
    private void btnCallAsync_OnClicked(object sender, EventArgs e)
    {
        // Registers the listener for handling the result for the asynchronous call
        bogus.BogusCompleted += new BogusEventHandler(bogus_BogusCompleted);

        // The "please wait" message
        lblText.Text = "Please wait while operation is processed...";

        // Run the BackgroundWorker thread
        bgWorker.RunWorkerAsync();
    }

    // Handles cancelation of the asynchronous call
    private void btnCancel_OnClicked(object sender, EventArgs e)
    {
        // Let's unregister the listener so that the asynchronous call
        // result is not handled
        bogus.BogusCompleted -= new BogusEventHandler(bogus_BogusCompleted);

        // Removes the "please wait" message
        lblText.Text = string.Empty;

        // Cancels the BackgroundWorker thread
        bgWorker.CancelAsync();
    }
    #endregion Button handlers

    private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        // Let's run it unless the BackgroundWorker is pending
        // cancelation
        if(!bgWorker.CancellationPending)
        {
            // This is not UI thread, since we are inside the
            // BackgroundWorker execution thread
            Thread.Sleep(new TimeSpan(0, 0, 3));

            // After sleeping for some time to allow users to read
            // the message, we start the asynchronous call
            bogus.RunBogusAsync();
        }
    }

    private void bogus_BogusCompleted(sender object, BogusEventArgs e)
    {
        // Any operations you want to execute in the UI thread
        // as a result of the asynchronous call
        Dispatcher.BeginInvoke(() =&gt; { UIOperations(); });

        // Unregister the listener since the call was already processed
        // and it is registered back on btnCallAsync_OnClicked()
        bogus.BogusCompleted -= new BogusEventHandler(bogus_BogusCompleted);
    }
}</pre>
<p>So now let&#8217;s see in detail what the above code does.</p>
<p>The xaml file includes three controls: <em>lblText</em> (<em>TextBlock</em> control), <em>btnCallAsync</em> and <em>btnCancel</em> (<em>Button</em> controls).</p>
<p>As shown on <em>btnCallAsync_OnClicked()</em> (lines 27 to 37), <em>lblText</em> will display the wait message when <em>btnCallAsync</em> is clicked. Additionally, it will register the listener for <em>BogusCompleted</em> event and trigger the execution of the background worker.</p>
<p><em>bgWorker_DoWork()</em> (lines 54 to 68) will then sleep the <em>BackgroundWorker</em> thread for a while and finally call the asynchronous method <em>RunBogusAsync()</em> which we were originally interested in.</p>
<p>On <em>BogusCompleted</em>, <em>bogus_BogusCompleted()</em> (lines 70 to 79) is finally run and <em>Dispatcher.BeginInvoke()</em> is called (using lambda expressions) to run something on the UI thread. We also unregister the listener for <em>BogusCompleted</em> events, since it is registered back every time <em>btnCallAsync</em> is clicked.</p>
<p>Sure we have a problem in this approach: we sleep the thread for some seconds before calling the asynchronous call, and that might cause a long wait in case <em>Bogus.RunBogusAsync()</em> takes too long to execute. For example, if the asynchronous call took five seconds to complete, we would keep the user waiting for eight seconds.</p>
<p>As an exercise, put the <em>BackgroundWorker</em> thread to sleep after the call to <em>Bogus.RunBogusAsync()</em>, and only if the asynchronous call didn&#8217;t take more than three seconds, so that the total wait would be at least three seconds, but no unnecessary extra time when.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2009/02/wait-messages-and-asynchronous-calls-in-silverlight-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Let&#8217;s try it in English</title>
		<link>http://www.nerdcore.com.br/blog/2009/02/lets-try-it-in-english/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=lets-try-it-in-english</link>
		<comments>http://www.nerdcore.com.br/blog/2009/02/lets-try-it-in-english/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 16:39:45 +0000</pubDate>
		<dc:creator>Rafael Costa</dc:creator>
				<category><![CDATA[blog]]></category>

		<guid isPermaLink="false">http://www.nerdcore.com.br/blog/?p=65</guid>
		<description><![CDATA[Já que possivelmente ninguém lê isso aqui, e agora que voltei a trabalhar com desenvolvimento novamente penso em escrever mais frequentemente (droga, sem tremas!), pensei em começar a escrever no blog em inglês. Acho que desse jeito um número maior de pessoas poderá se beneficiar, via google e outros, dos assuntos tratados nos posts. Yep, [...]]]></description>
			<content:encoded><![CDATA[<p>Já que possivelmente ninguém lê isso aqui, e agora que voltei a trabalhar com desenvolvimento novamente penso em escrever mais frequentemente (droga, sem tremas!), pensei em começar a escrever no blog em inglês.</p>
<p>Acho que desse jeito um número maior de pessoas poderá se beneficiar, via google e outros, dos assuntos tratados nos posts.</p>
<p>Yep, it&#8217;s in English from now on.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdcore.com.br/blog/2009/02/lets-try-it-in-english/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

