<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns: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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Buu Nguyen's Blog</title>
	
	<link>http://www.buunguyen.net/blog</link>
	<description>Thoughts on Software Engineering</description>
	<lastBuildDate>Fri, 07 May 2010 12:58:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/BuuNguyensBlog" /><feedburner:info uri="buunguyensblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>BuuNguyensBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Handle all uncaught exceptions thrown when using Task Parallel Library (take 2)</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/8lYQmpngJGo/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library-take-2.html</link>
		<comments>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library-take-2.html#comments</comments>
		<pubDate>Fri, 07 May 2010 12:57:53 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[tpl]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=505</guid>
		<description><![CDATA[A couple of days ago I posted a solution to handle all uncaught exceptions when using TPL.  I&#8217;ve found a better way to do that, making use of task continuation.  The class ThreadFactory below exposes the Error event which can be subscribed by a top-level handler and provides methods to start a task [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I posted <a href="http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html">a solution to handle all uncaught exceptions when using TPL</a>.  I&#8217;ve found a better way to do that, making use of task continuation.  The class <code>ThreadFactory</code> below exposes the <code>Error</code> event which can be subscribed by a top-level handler and provides methods to start a task attached with proper continuation.</p>
<pre class="brush:csharp">internal class ThreadFactory
{
    public delegate void TaskError(Task task, Exception error);

    public static readonly ThreadFactory Instance = new ThreadFactory();

    private ThreadFactory() {}

    public event TaskError Error;

    public void InvokeError(Task task, Exception error)
    {
        TaskError handler = Error;
        if (handler != null) handler(task, error);
    }

    public void Start(Action action)
    {
        var task = new Task(action);
        Start(task);
    }

    public void Start(Action action, TaskCreationOptions options)
    {
        var task = new Task(action, options);
        Start(task);
    }

    private void Start(Task task)
    {
        task.ContinueWith(t =&gt; InvokeError(t, t.Exception.InnerException),
                            TaskContinuationOptions.OnlyOnFaulted |
                            TaskContinuationOptions.ExecuteSynchronously);
        task.Start();
    }
}</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fhandle-all-uncaught-exceptions-thrown-when-using-task-parallel-library-take-2.html&amp;linkname=Handle%20all%20uncaught%20exceptions%20thrown%20when%20using%20Task%20Parallel%20Library%20%28take%202%29"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=8lYQmpngJGo:3CpLoCmspuo:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=8lYQmpngJGo:3CpLoCmspuo:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=8lYQmpngJGo:3CpLoCmspuo:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=8lYQmpngJGo:3CpLoCmspuo:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=8lYQmpngJGo:3CpLoCmspuo:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library-take-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library-take-2.html</feedburner:origLink></item>
		<item>
		<title>Handle all uncaught exceptions thrown when using Task Parallel Library</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/SPnyjCXVjRs/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html</link>
		<comments>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html#comments</comments>
		<pubDate>Tue, 04 May 2010 16:53:05 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[concurrency]]></category>
		<category><![CDATA[multithreading]]></category>
		<category><![CDATA[tpl]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=494</guid>
		<description><![CDATA[I&#8217;m using the TPL (Task Parallel Library) in .NET 4.0. I want to be able to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads started with TPL code, e.g. Task.Factory.StartNew(...). The event is indeed fired if I use something [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using the TPL (<a href="http://msdn.microsoft.com/en-us/library/dd460717%28v=VS.100%29.aspx">Task Parallel Library</a>) in .NET 4.0. I want to be able to centralize the handling logic of all unhandled exceptions by using the <code>Thread.GetDomain().UnhandledException</code> event. However, in my application, the event is never fired for threads started with TPL code, e.g. <code>Task.Factory.StartNew(...)</code>. The event is indeed fired if I use something like <code>new Thread(threadStart).Start()</code>.</p>
<p><a href="http://msdn.microsoft.com/en-us/library/dd997415%28v=VS.100%29.aspx">This MSDN article</a> suggests to use <code>Task#Wait()</code> to catch the <code>AggregateException</code> when working with TPL, but that is not I want because it is not &#8220;centralized&#8221; enough a mechanism. </p>
<p>I&#8217;ve posted the above issue (verbatim) in <a href="http://stackoverflow.com/questions/2707295/how-to-handle-all-unhandled-exceptions-when-using-task-parallel-library">this StackOverflow question</a> but didn&#8217;t receive any response.  So, I had to roll out some custom code to do that.  Below is the description of the solution for those who are interested.</p>
<p>The general idea is pretty simple.  First, we need to know all the currently executed tasks.  Since there&#8217;s <a href="http://stackoverflow.com/questions/1551537/is-there-a-way-to-tell-which-tasks-are-currently-running-in-task-parallel-library">no built-in way</a> to know which tasks are being executed, we need to intercept the task addition.  The class <code>TaskFactoryWrapper</code> below does just that.</p>
<pre class="brush:csharp">static class TaskFactoryWrapper
{
    public static void Start(Action action)
    {
        var task = new Task(action);
        TaskErrorWatcher.Instance.AddTask(task);
        task.Start();
    }

    public static void Start(Action action, TaskCreationOptions options)
    {
        var task = new Task(action, options);
        TaskErrorWatcher.Instance.AddTask(task);
        task.Start();
    }
}
</pre>
<p>Inside the class <code>TaskErrorWatcher</code>, there&#8217;s a worker thread which periodically checks each task to see if the latter already finishes, is canceled or causes an error.  If it causes an error, the worker thread trigger the error event.  </p>
<pre class="brush:csharp">class TaskErrorWatcher
{
    public delegate void TaskError(Task task, Exception error);
    private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
    private static readonly TaskErrorWatcher @Instance = new TaskErrorWatcher();

    public static TaskErrorWatcher Instance
    {
        get
        {
            return @Instance;
        }
    }

    private TaskErrorWatcher()
    {
        Task.Factory.StartNew(Monitor);
    }

    public event TaskError Error;

    public void InvokeError(Task task, Exception error)
    {
        TaskError handler = Error;
        if (handler != null) handler(task, error);
    }

    private readonly List&lt;Task&gt; tasks = new List&lt;Task&gt;();
    private readonly object syncLock = new object();

    public void AddTask(Task task)
    {
        lock (syncLock)
        {
            tasks.Add(task);
        }
    }

    private void Monitor()
    {
        Utils.Interval(3000, () =&gt;
                                {
                                    lock (syncLock)
                                    {
                                        for (int i = tasks.Count - 1; i &gt;= 0; i--)
                                        {
                                            var task = tasks[i];
                                            if (task.IsFaulted)
                                            {
                                                InvokeError(task, task.Exception);
                                            }
                                            if (task.IsCanceled || task.IsCompleted)
                                            {
                                                tasks.RemoveAt(i);
                                            }
                                        }
                                    }
                                },
                                ex =&gt; Log.Error(ex));
    }
}</pre>
<p><code>Utils.Interval</code> is simply a helper method which repeatedly executes an action when the specified interval has elapsed.</p>
<pre class="brush:csharp">public static void Interval(long interval, Action action, Action&lt;Exception&gt; errorHandler = null)
{
    var watch = Stopwatch.StartNew();
    while (true)
    {
        try
        {
            action();
            watch.Stop();
            Thread.Sleep((int)Math.Max(0, interval - watch.ElapsedMilliseconds));
            watch.Restart();
        }
        catch (Exception ex)
        {
            if (errorHandler == null)
                throw;
            errorHandler(ex);
        }
    }
}</pre>
<p>Now, in the top level code (e.g. inside <code>Main()</code>), just subscribe to the <code>Error</code> event of <code>TaskErrorWatcher</code> and do whatever you want to do in case of error, e.g. </p>
<pre class="brush:csharp">TaskErrorWatcher.Instance.Error += (_, error) =&gt; HandleError(error);</pre>
<p>That&#8217;s it.  Hope it helps!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fhandle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html&amp;linkname=Handle%20all%20uncaught%20exceptions%20thrown%20when%20using%20Task%20Parallel%20Library"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SPnyjCXVjRs:1sIdbVwW-9k:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SPnyjCXVjRs:1sIdbVwW-9k:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=SPnyjCXVjRs:1sIdbVwW-9k:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SPnyjCXVjRs:1sIdbVwW-9k:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=SPnyjCXVjRs:1sIdbVwW-9k:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/handle-all-uncaught-exceptions-thrown-when-using-task-parallel-library.html</feedburner:origLink></item>
		<item>
		<title>Speaking at the Visual Studio.NET 2010 Launch in Hanoi</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/3uuctGS8OGU/speaking-on-the-visual-studio-net-2010-launch-in-hanoi.html</link>
		<comments>http://www.buunguyen.net/blog/speaking-on-the-visual-studio-net-2010-launch-in-hanoi.html#comments</comments>
		<pubDate>Mon, 19 Apr 2010 16:52:26 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[events]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=475</guid>
		<description><![CDATA[Last Tuesday, I spoke at the Visual Studio.NET 2010 launch in Hanoi.  It was a big launch with about 400 attendees.  I hosted 2 sessions, one about ASP.NET 4.0 (including web forms, MVC, AJAX and dynamic data) and another about C# 4.0 and PLINQ.  On the following day, I spoke at Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p>Last Tuesday, I spoke at the Visual Studio.NET 2010 launch in Hanoi.  It was a big launch with about 400 attendees.  I hosted 2 sessions, one about ASP.NET 4.0 (including web forms, MVC, AJAX and dynamic data) and another about C# 4.0 and PLINQ.  On the following day, I spoke at Microsoft Vietnam&#8217;s office about building scalable .NET web applications to about 40 .NET architects and developers in Hanoi.</p>
<p>In general, it was a great trip to Hanoi and I had a lot of fun speaking and meeting many people there.  The sessions by other speakers were really great.  I was particular impressed with what Silverlight 4.0 and SharePoint 2010 had to offer.</p>
<p>You can find the slides and sample code I used for these sessions below.</p>
<div id="__ss_3767180" style="width: 425px;"><strong style="display:block;margin:12px 0 4px"><a title="New Features of ASP.NET 4.0" href="http://www.slideshare.net/buunguyen/new-features-of-aspnet-40">New Features of ASP.NET 4.0</a></strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newfeaturesofasp-net4-0-100418115205-phpapp01&amp;rel=0&amp;stripped_title=new-features-of-aspnet-40" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=newfeaturesofasp-net4-0-100418115205-phpapp01&amp;rel=0&amp;stripped_title=new-features-of-aspnet-40" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/buunguyen">Buu Nguyen</a>.</div>
</div>
<div id="__ss_3767176" style="width: 425px;"><strong style="display:block;margin:12px 0 4px"><a title="C# 4.0 and .NET 4.0" href="http://www.slideshare.net/buunguyen/c-40-and-net-40">C# 4.0 and .NET 4.0</a></strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c4-0and-net4-0-100418115106-phpapp02&amp;rel=0&amp;stripped_title=c-40-and-net-40" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=c4-0and-net4-0-100418115106-phpapp02&amp;rel=0&amp;stripped_title=c-40-and-net-40" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/buunguyen">Buu Nguyen</a>.</div>
</div>
<div id="__ss_3767182" style="width: 425px;"><strong style="display:block;margin:12px 0 4px"><a title="Building Scalable .NET Web Applications" href="http://www.slideshare.net/buunguyen/building-scalable-net-web-applications">Building Scalable .NET Web Applications</a></strong><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=scalabilitybestpractices-100418115259-phpapp01&amp;rel=0&amp;stripped_title=building-scalable-net-web-applications" /><param name="allowfullscreen" value="true" /><embed type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=scalabilitybestpractices-100418115259-phpapp01&amp;rel=0&amp;stripped_title=building-scalable-net-web-applications" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/buunguyen">Buu Nguyen</a>.</div>
</div>
<p><strong>Sample code can be downloaded <a href="http://cid-acbe40cad17efb78.skydrive.live.com/browse.aspx/Public/VS.NET%202010%20Launch%20Demo">here</a></strong></p>
<p><strong>Some pictures taken (click to view larger images)<br />
</strong></p>
<p><strong><a href="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_34461.JPG"><img class="alignnone size-medium wp-image-484" title="VS.NET 2010 Launch Event" src="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_34461-300x225.jpg" alt="VS.NET 2010 Launch Event" width="300" height="225" /></a></strong></p>
<p><strong><a href="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_3454.JPG"><img class="alignnone size-medium wp-image-485" title="Tea Break during the VS.NET 2010 Launch" src="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_3454-300x225.jpg" alt="Tea Break during the VS.NET 2010 Launch" width="300" height="225" /></a><br />
</strong></p>
<p><a href="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_3535.JPG"><img class="alignnone size-medium wp-image-487" title=".NET Web Scalability Presentation at Microsoft Vietnam's Office" src="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_3535-300x225.jpg" alt=".NET Web Scalability Presentation at Microsoft Vietnam's Office" width="300" height="225" /></a></p>
<p><a href="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_34951.JPG"><img class="alignnone size-medium wp-image-486" title="Tea Break during the Scalability Presentation" src="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/IMG_34951-300x225.jpg" alt="Tea Break during the Scalability Presentation" width="300" height="225" /></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fspeaking-on-the-visual-studio-net-2010-launch-in-hanoi.html&amp;linkname=Speaking%20at%20the%20Visual%20Studio.NET%202010%20Launch%20in%20Hanoi"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=3uuctGS8OGU:kROaVxtok5M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=3uuctGS8OGU:kROaVxtok5M:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=3uuctGS8OGU:kROaVxtok5M:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=3uuctGS8OGU:kROaVxtok5M:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=3uuctGS8OGU:kROaVxtok5M:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/speaking-on-the-visual-studio-net-2010-launch-in-hanoi.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/speaking-on-the-visual-studio-net-2010-launch-in-hanoi.html</feedburner:origLink></item>
		<item>
		<title>I’m a Microsoft MVP!</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/ML0sdbjMSNI/im-a-microsoft-mvp.html</link>
		<comments>http://www.buunguyen.net/blog/im-a-microsoft-mvp.html#comments</comments>
		<pubDate>Fri, 02 Apr 2010 15:57:23 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[awards]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[mvp]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=461</guid>
		<description><![CDATA[An email from Microsoft, starting with &#8220;Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in ASP/ASP.NET technical communities during the past year.&#8221; has made my [...]]]></description>
			<content:encoded><![CDATA[<p>An email from Microsoft, starting with <em>&#8220;Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in ASP/ASP.NET technical communities during the past year.&#8221;</em> has made my day.  </p>
<p>It&#8217;s official, I am a <a href="https://mvp.support.microsoft.com/gp/mvpintro">Microsoft MVP</a>!  (Click <a href="https://mvp.support.microsoft.com/profile=CD4C665B-E29C-4D89-AF18-9E9EDDDE4228">here</a> to see my profile.)  One can&#8217;t help feeling honored knowing that he is  <a href="https://mvp.support.microsoft.com/gp/mvpfaqs">one of the selected 4,000 in 100 million technical community participants worldwide</a> and <a href="http://seamvpblogaholic.spaces.live.com/">among the 12 MVPs in Vietnam</a>.  I am honored.  </p>
<p>My sincere thanks to the employees at Microsoft who nominated and joined me in many community projects during the past year!  I truly enjoy working with you and I am looking forwards to future projects.</p>
<p style="text-align: center;"><a><img class="size-full wp-image-463 aligncenter" title="MVP-h-550x222" src="http://www.buunguyen.net/blog/wp-content/uploads/2010/04/MVP-h-550x222.png" alt="MVP-h-550x222" width="550" height="222" /></a></p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fim-a-microsoft-mvp.html&amp;linkname=I%26%238217%3Bm%20a%20Microsoft%20MVP%21"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=ML0sdbjMSNI:PKgWEfa2GzI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=ML0sdbjMSNI:PKgWEfa2GzI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=ML0sdbjMSNI:PKgWEfa2GzI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=ML0sdbjMSNI:PKgWEfa2GzI:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=ML0sdbjMSNI:PKgWEfa2GzI:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/im-a-microsoft-mvp.html/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/im-a-microsoft-mvp.html</feedburner:origLink></item>
		<item>
		<title>ASP.NET MVC Validation Library 1.3 Release</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/75XBVyeTuwA/asp-net-mvc-validation-library-1-3-release.html</link>
		<comments>http://www.buunguyen.net/blog/asp-net-mvc-validation-library-1-3-release.html#comments</comments>
		<pubDate>Wed, 31 Mar 2010 15:13:37 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=456</guid>
		<description><![CDATA[This is truly a month of release.  In fact, I released Fasterflect 2.0 and Combres 2.0 within the past 10 days.  And now, it&#8217;s ASP.NET MVC Validation Library 1.3.  It&#8217;s not like I suddenly have all the time in the world to push the releases of these libraries.  Instead, code gets [...]]]></description>
			<content:encoded><![CDATA[<p>This is truly a month of release.  In fact, I released <a href="http://www.buunguyen.net/blog/fasterflect-2-0-release.html">Fasterflect 2.0</a> and <a href="http://www.buunguyen.net/blog/combres-2-0-release.html">Combres 2.0</a> within the past 10 days.  And now, it&#8217;s <a href="http://aspmvcvalidation.codeplex.com/releases/view/42860">ASP.NET MVC Validation Library 1.3</a>.  It&#8217;s not like I suddenly have all the time in the world to push the releases of these libraries.  Instead, code gets accumulated over the last 3-4 months until they happen to be done at the same time.  Anyway, a couple of notes about this release of ASP.NET MVC Validation Library.</p>
<p>First and foremost, if you are using ASP.NET MVC 2.0, then you can stop reading.  This library is not for you.  Really, ASP.NET MVC 2.0 comes with a highly robust and flexible validation functionality built-in already, so there&#8217;s no reason to look for a 3rd-party library which has nothing more to offer.  That said, if you are still stuck with some ASP.NET MVC 1.0 legacy apps, like me, then my library can be useful.  </p>
<p>If you are not familiar with this library, please refer to <a href="http://www.buunguyen.net/blog/aspnet-mvc-validation-library.html">this originally introductory post</a> to learn how to use it.  Because I haven&#8217;t taken the time to posted about the all of changes since the release mentioned in that post, I&#8217;m doing it now.</p>
<p><strong>Changes in 1.3</strong></p>
<ul>
<li>Support custom server-side validation</li>
<li>Support remote validation (integrated with jQuery Validate&#8217;s <em>remote</em> method)</li>
<li>The design of validation attributes is improved to make addition of new validation attribute much more intuitive</li>
</ul>
<p><strong>Changes in 1.2</strong></p>
<ul>
<li>Support RegularExpressionValidatorAttribute (use the property ClientFunctionName to specify the corresponding jQuery Validate&#8217;s function)</li>
<li>Allow specify a custom form validation function (i.e. instead of the default $(formName).validate())</li>
<li>Support PropertyComparisonValidatorAttribute (equal operator only)</li>
<li>EntityValidationException adds constructor to accept custom key-value pair (i.e. useful for non-model/custom validations)</li>
<li>Support specifying custom ready function (i.e. useful when using a 3rd-party script loader, like Google&#8217;s, to load jQuery)</li>
<li>Support specifying custom client ID (in case the client-side <em>ID</em> is different from the client-side <em>name</em> (used for posted value)</li>
</ul>
<p><strong>Changes in 1.1</strong></p>
<ul>
<li>Eliminate the need to specify type parameter when invoking Validate() method</li>
<li>Allow users to specify prefix when populating model state with error messages</li>
</ul>
<p>That&#8217;s it for the post.  That&#8217;s it?  Yes, that&#8217;s it.  The library is ridiculously easy to use, so you don&#8217;t need another 10 pages of tutorial here.  Instead, the old introductory article, together with the above change notices, should be enough for you to start working with the library.  Okay, it might not be that easy.  Don&#8217;t worry yet, <a href="http://aspmvcvalidation.codeplex.com/releases/view/42860#DownloadId=113637">the download of ASP.NET MVC Validation Library</a> comes with CHM API documentation and a sample application that uses almost all features of the library.  So, download and explore the library yourself.  And post here if you have any comment or feedback.  Enjoy!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fasp-net-mvc-validation-library-1-3-release.html&amp;linkname=ASP.NET%20MVC%20Validation%20Library%201.3%20Release"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=75XBVyeTuwA:iek7fXUVQD4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=75XBVyeTuwA:iek7fXUVQD4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=75XBVyeTuwA:iek7fXUVQD4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=75XBVyeTuwA:iek7fXUVQD4:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=75XBVyeTuwA:iek7fXUVQD4:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/asp-net-mvc-validation-library-1-3-release.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/asp-net-mvc-validation-library-1-3-release.html</feedburner:origLink></item>
		<item>
		<title>Combres 2.0 Release</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/LFGTCiiKUYM/combres-2-0-release.html</link>
		<comments>http://www.buunguyen.net/blog/combres-2-0-release.html#comments</comments>
		<pubDate>Tue, 30 Mar 2010 14:15:00 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[combres]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=454</guid>
		<description><![CDATA[After a couple of months working on and off on this project, I was finally able to release the next major version of Combres, a .NET library which automates the application of many website optimization techniques in ASP.NET MVC or ASP.NET Web Forms applications.
Access to this CodePlex page to download Combres 2.0, together with source [...]]]></description>
			<content:encoded><![CDATA[<p>After a couple of months working on and off on this project, I was finally able to release the next major version of Combres, a .NET library which automates the application of many website optimization techniques in ASP.NET MVC or ASP.NET Web Forms applications.</p>
<p>Access to <a href="http://combres.codeplex.com/releases/view/42329">this CodePlex page</a> to download Combres 2.0, together with source code, CHM API documentation, sample applications and config files.</p>
<p>For a full introduction to Combres 2.0, refer to <a href="http://www.codeproject.com/KB/aspnet/combres2.aspx">this Code Project article</a>.</p>
<p>Enjoy the improved performance!</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fcombres-2-0-release.html&amp;linkname=Combres%202.0%20Release"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=LFGTCiiKUYM:AW70K4VSnfM:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=LFGTCiiKUYM:AW70K4VSnfM:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=LFGTCiiKUYM:AW70K4VSnfM:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=LFGTCiiKUYM:AW70K4VSnfM:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=LFGTCiiKUYM:AW70K4VSnfM:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/combres-2-0-release.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/combres-2-0-release.html</feedburner:origLink></item>
		<item>
		<title>Fasterflect 2.0 Release</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/dhiCtwxCP38/fasterflect-2-0-release.html</link>
		<comments>http://www.buunguyen.net/blog/fasterflect-2-0-release.html#comments</comments>
		<pubDate>Sun, 21 Mar 2010 10:32:02 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dynamic-method]]></category>
		<category><![CDATA[emit]]></category>
		<category><![CDATA[fasterflect]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=443</guid>
		<description><![CDATA[I am pleased to announce the release of Fasterflect 2.0.  For those who are not aware of Fasterflect, it is a library that helps you get rid of the complexity and slow performance of .NET Reflection.  Check out this Code Project article and a previous announcement for an introduction.  
Fasterflect 2.0 comes [...]]]></description>
			<content:encoded><![CDATA[<p>I am pleased to announce the release of <a href="http://fasterflect.codeplex.com/releases/view/40783">Fasterflect 2.0</a>.  For those who are not aware of Fasterflect, it is a library that helps you get rid of the complexity and slow performance of .NET Reflection.  Check out <a href="http://www.codeproject.com/KB/library/fasterflect_.aspx">this Code Project article</a> and <a href="http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html">a previous announcement</a> for an introduction.  </p>
<p>Fasterflect 2.0 comes with a great number of additions &#038; changes, which are possible thanks to the fact that I am no longer the only developer of this project;  instead, Morten Mertner (author of <a href="http://sourceforge.net/projects/gopf/">Gentle.NET</a>) has joined me since the beginning of 2.0 and made huge contribution ever since.  Let&#8217;s look at some highlights of this release.</p>
<p>The most exciting addition in this release is that Fasterflect now includes a <a href="http://fasterflect.codeplex.com/wikipage?title=Querying">Query API</a>.  Previously you can only use Fasterflect to construct objects or performs invocations (these 2 usages are now referred as <a href="http://fasterflect.codeplex.com/wikipage?title=Accessing">Access API</a>).  With this release, you can query .NET reflection metadata with Fasterflect although much simpler than what you have to do with the built-in .NET reflection.  You can even do more thing with this Query API than you can with .NET reflection out of the box.  For example, you can choose to exclude backing members from a lookup or enable partial-name lookup.  All you need to do in order to have these level of control is specifying a proper Fasterflect <a href="http://fasterflect.codeplex.com/wikipage?title=Getting Started#flags">binding flag</a>.  The nice thing about Fasterflect binding flag is that it is also fully supported in the Access API.</p>
<p>Next, the Access API is now fully integrated with .NET reflection metadata classes, such as ConstructorInfo, MethodInfo, FieldInfo etc.  This integration makes it able for you to mix &#038; match the usages of Query API and Access API as well as allows you to use .NET reflection as it is while delegating the invocation to the fast CIL-generation engine of Fasterflect.  </p>
<p>We have also built on top of the core Fasterflect engine some <a href="http://fasterflect.codeplex.com/wikipage?title=Services">add-on services</a> such as <a href="http://fasterflect.codeplex.com/wikipage?title=Advanced%20Object%20Construction">advanced object construction</a>, <a href="http://fasterflect.codeplex.com/wikipage?title=Deep%20Cloning">deep cloning</a> and <a href="http://fasterflect.codeplex.com/wikipage?title=Object%20Mapping">object mapping</a>.  We expect to have more of these services in future releases and of course, you can send us your contributions too.</p>
<p>Users of previous versions of Fasterflect should be aware of the following breaking changes.</p>
<ul>
<li>Many existing extension methods have their names changed as we went through the process of improving API&#8217;s consistency &#038; usability.  We hope these changes are for the better because now we have 2 developers vote on the conventions instead of 1 like previously <img src='http://www.buunguyen.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .  You would have to make some code change when switching from 1.1 to 2.0, but the changes should be very straight-forward in most cases except for the other changes described below.
 </li>
<li>Fasterflect extension methods now don&#8217;t require a type parameter, which we have found to be inconvenient because people are forced to append &lt;object&gt; to the call even when they don&#8217;t care about the return value or its type. These methods now simply return result of type System.Object and you can cast to the correct type if you need to.</li>
<li>Batch fields/properties setting are gone. They are replaced by the object mapping add-on service which is more flexible, sophisticated and faster (CIL code generation is used behind the scene). Batch setting of static members is not supposed though because we think it&#8217;s not a common scenario.  That said, do let us know if you have this need and we will add support for it in the next minor release.</li>
<li>The class Reflector and its methods are now gone. We instead employ a custom-built weak reference-based cache to assure that generated CIL can be garbage-collected when memory is low.</li>
</ul>
<p>Last but not least, the <a href="http://fasterflect.codeplex.com/documentation">project wiki</a> on CodePlex is fully populated with comprehensive documentation.  While Fasterflect is still ridiculously easy to use, it now has a much bigger API and is more sophisticated than it used to be (e.g. with Fasterflect binding flags).  Therefore, documentation should be of great help for those who want to understand everything about Fasterflect to use it effectively in even advanced scenarios without having to dig through the source code.</p>
<p>You can download the binary, source code and CHM API help file in the <a href="http://fasterflect.codeplex.com/releases/view/40783">Fasterflect 2.0 release page</a> in CodePlex.  If you want to explore Fasterflect in details, surf through the <a href="http://fasterflect.codeplex.com/documentation">project wiki</a>.  If you just want to jump right into the usages without any further introduction, check out the <a href="http://fasterflect.codeplex.com/wikipage?title=2-Minute%20Guide%20To%20Accessing%20API&#038;referringTitle=Documentation">2-minute-guide to Access API</a> and this page about the <a href="http://fasterflect.codeplex.com/wikipage?title=Standard Queries">Query API</a>.  Finally, the comprehensive unit test suite included in the code download can also serve as good reference for the API.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Ffasterflect-2-0-release.html&amp;linkname=Fasterflect%202.0%20Release"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=dhiCtwxCP38:QJUWhqSVxVs:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=dhiCtwxCP38:QJUWhqSVxVs:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=dhiCtwxCP38:QJUWhqSVxVs:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=dhiCtwxCP38:QJUWhqSVxVs:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=dhiCtwxCP38:QJUWhqSVxVs:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/fasterflect-2-0-release.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/fasterflect-2-0-release.html</feedburner:origLink></item>
		<item>
		<title>Fasterflect vs. C# 4.0 Dynamic</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/SaQZlCLWfcw/fasterflect-vs-c-4-0-dynamic.html</link>
		<comments>http://www.buunguyen.net/blog/fasterflect-vs-c-4-0-dynamic.html#comments</comments>
		<pubDate>Thu, 31 Dec 2009 14:55:29 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[fasterflect]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=430</guid>
		<description><![CDATA[As .NET 4.0 final release will hit the market pretty soon, it&#8217;s worth discussing the value of Fasterflect in the face of C# 4.0&#8217;s dynamic keyword.  (If you aren&#8217;t familiar with C# 4.0 dynamic, you should read my article on C# 4.0 before continuing.)
To recall, Fasterflect was designed to address 2 key disadvantages of .NET [...]]]></description>
			<content:encoded><![CDATA[<p>As .NET 4.0 final release will hit the market pretty soon, it&#8217;s worth discussing the value of <a href="http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html">Fasterflect</a> in the face of C# 4.0&#8217;s dynamic keyword.  (If you aren&#8217;t familiar with C# 4.0 dynamic, you should read <a href="http://www.codeproject.com/KB/cs/csharp_4_overview.aspx">my article on C# 4.0</a> before continuing.)</p>
<p>To recall, Fasterflect was designed to address 2 key disadvantages of .NET Reflection: ease of use and performance.  As seen in my article about C# 4.0, the dynamic keyword nicely addresses the easy of use with a resulting syntax looking even nicer than Fasterflect.  How about performance?</p>
<p>I improved the <a href="http://www.codeproject.com/KB/library/fasterflect_.aspx">benchmark application</a> of Fasterflect to add some benchmark code comparing between the performance of C# 4.0 dynamic and Fasterflect.  Here is result of method invocation benchmark.</p>
<p><img class="alignnone size-full wp-image-431" title="fasterflectbenchmark" src="http://www.buunguyen.net/blog/wp-content/uploads/2009/12/fasterflectbenchmark.png" alt="fasterflectbenchmark" width="384" height="143" /></p>
<p>While performing slower than Fasterflect&#8217;s cached API, C# dynamic performs much better than Fasterflect&#8217;s standard API.  (Not surprisingly, the C# dynamic binding doesn&#8217;t resort to the slow reflection mechanism internally.)</p>
<p>With this awareness in mind, together with the understanding about the features of C# dynamic and Fasterflect, let&#8217;s discuss about areas where Fasterflect shines even in the face of C# 4.0 dynamic:</p>
<ul>
<li>C# dynamic doesn&#8217;t handle invocations performed based on dynamic information (i.e. field name read from XML file).</li>
<li>C# dynamic does handle certain types of dynamic invocations, including static method invocation, static property invocation and constructor invocation.</li>
<li>C# dynamic doesn&#8217;t handle non-public members.  So you&#8217;ll receive exception if trying to, say, invoke a private method.</li>
<li>When performance is more critical than readability then the Fasterflect&#8217;s cached API might be favored over C# dynamic.</li>
</ul>
<p>Granted, there should be workarounds for the first 3 items.  For example, if you want to invoke static method dynamically with C# dynamic, you would have to workaround like the approach described in <a href="http://blogs.msdn.com/davidebb/archive/2009/10/23/using-c-dynamic-to-call-static-members.aspx">this article</a>.  However, the approach uses reflection behind the scene so you would have the same performance issue to start with.</p>
<p>This doesn&#8217;t say that Fasterflect is better than C# dynamic though.  While both share a couple of features and maybe used interchangeably in some scenarios, they also have different problems of their own to address.  There are many things that you can do with C# dynamic that you couldn&#8217;t do with Fasterflect, e.g. implementing an interceptor to dynamically handle all method invocations (or missing methods) etc.  So, pick the right tool for your problem at hand.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Ffasterflect-vs-c-4-0-dynamic.html&amp;linkname=Fasterflect%20vs.%20C%23%204.0%20Dynamic"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SaQZlCLWfcw:PZhx4tcpVLc:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SaQZlCLWfcw:PZhx4tcpVLc:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=SaQZlCLWfcw:PZhx4tcpVLc:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=SaQZlCLWfcw:PZhx4tcpVLc:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=SaQZlCLWfcw:PZhx4tcpVLc:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/fasterflect-vs-c-4-0-dynamic.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/fasterflect-vs-c-4-0-dynamic.html</feedburner:origLink></item>
		<item>
		<title>Speaking at Barcamp Saigon 2009</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/jgN9ajZBEv4/speaking-at-barcamp-saigon-2009.html</link>
		<comments>http://www.buunguyen.net/blog/speaking-at-barcamp-saigon-2009.html#comments</comments>
		<pubDate>Wed, 16 Dec 2009 14:09:22 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[barcampsaigon]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[combres]]></category>
		<category><![CDATA[community]]></category>
		<category><![CDATA[fasterflect]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=414</guid>
		<description><![CDATA[I spoke at Barcamp Saigon 2009 last Sunday.  It was a fun event.  Met a number of interesting people and learned some new things from other sessions.  I talked about the two open-source libraries I developed, Fasterflect &#38; Combres.  Below are the slides I used for my presentations.
Fasterflect
View more presentations from [...]]]></description>
			<content:encoded><![CDATA[<p>I spoke at <a href="http://www.barcampsaigon.org/">Barcamp Saigon 2009</a> last Sunday.  It was a fun event.  Met a number of interesting people and learned some new things from other sessions.  I talked about the two open-source libraries I developed, <a href="http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html">Fasterflect</a> &amp; <a href="http://www.buunguyen.net/blog/combres-webform-mvc-client-side-resource-combine-library.html">Combres</a>.  Below are the slides I used for my presentations.</p>
<div style="width:425px;text-align:left" id="__ss_2713206"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/buunguyen/fasterflect" title="Fasterflect">Fasterflect</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=fasterflect-091214031041-phpapp02&#038;rel=0&#038;stripped_title=fasterflect" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=fasterflect-091214031041-phpapp02&#038;rel=0&#038;stripped_title=fasterflect" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/buunguyen">Buu Nguyen</a>.</div>
</div>
<div style="width:425px;text-align:left" id="__ss_2713208"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/buunguyen/combres" title="Combres">Combres</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=combres-091214031306-phpapp02&#038;rel=0&#038;stripped_title=combres" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=combres-091214031306-phpapp02&#038;rel=0&#038;stripped_title=combres" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View more <a style="text-decoration:underline;" href="http://www.slideshare.net/">presentations</a> from <a style="text-decoration:underline;" href="http://www.slideshare.net/buunguyen">Buu Nguyen</a>.</div>
</div>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fspeaking-at-barcamp-saigon-2009.html&amp;linkname=Speaking%20at%20Barcamp%20Saigon%202009"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=jgN9ajZBEv4:iVZ59z6qVjY:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=jgN9ajZBEv4:iVZ59z6qVjY:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=jgN9ajZBEv4:iVZ59z6qVjY:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=jgN9ajZBEv4:iVZ59z6qVjY:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=jgN9ajZBEv4:iVZ59z6qVjY:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/speaking-at-barcamp-saigon-2009.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/speaking-at-barcamp-saigon-2009.html</feedburner:origLink></item>
		<item>
		<title>.NET Reflection Made Fast &amp; Simple – Fasterflect 1.1 Release</title>
		<link>http://feedproxy.google.com/~r/BuuNguyensBlog/~3/YOj95rNdyu0/net-reflection-made-fast-simple-fasterflect-1-1-release.html</link>
		<comments>http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html#comments</comments>
		<pubDate>Thu, 19 Nov 2009 13:48:35 +0000</pubDate>
		<dc:creator>Buu Nguyen</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[dynamic-method]]></category>
		<category><![CDATA[emit]]></category>
		<category><![CDATA[fasterflect]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://www.buunguyen.net/blog/?p=398</guid>
		<description><![CDATA[I&#8217;m pleased to announce that version 1.1 of Fasterflect, the fast &#038; simple .NET reflection invocation library, is already released in CodePlex.  The download include Fasterflect binary, code documentation, benchmark application source, sample code, unit test source (95%+ coverage, can be used to learn about all usage aspect of Fasterflect).
For an introduction to Fasterflect, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pleased to announce that version 1.1 of Fasterflect, the fast &#038; simple .NET reflection invocation library, is already released in <a href="http://fasterflect.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=36129">CodePlex</a>.  The download include Fasterflect binary, code documentation, benchmark application source, sample code, unit test source (95%+ coverage, can be used to learn about all usage aspect of Fasterflect).</p>
<p>For an introduction to Fasterflect, including its design, APIs, and benchmark, please refer to <a href="http://www.codeproject.com/KB/library/fasterflect_.aspx">this Code Project article</a>.</p>
<p>Changes since version 1.0 beta (the one documented in the Code Project article) include:</p>
<ul>
<li>Support array types (construction, set element, get element)</li>
<li>Support structs </li>
<li>Support ref/out parameters</li>
<li>Support lookup by covariant parameter type</li>
<li>Inference of parameter types for non-null arguments</li>
<li>Several bug fixes</li>
</ul>
<p><strong>Sample Code</strong></p>
<pre class="brush:csharp">
class PersonClass
{
    private int id;
    private int milesTraveled;
    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    public string Name { get; private set; }
    private static int InstanceCount;

    public PersonClass() : this(0) {}

    public PersonClass(int id) : this(id, string.Empty) { }

    public PersonClass(int id, string name)
    {
        Id = id;
        Name = name;
        InstanceCount++;
    }

    public char this[int index]
    {
        get { return Name[index]; }
    }

    private void Walk(int miles)
    {
        milesTraveled += miles;
    }

    private static void IncreaseInstanceCount()
    {
        InstanceCount++;
    }

    private static int GetInstanceCount()
    {
        return InstanceCount;
    }

    public static void Swap(ref int i, ref int j)
    {
        int tmp = i;
        i = j;
        j = tmp;
    }
}
</pre>
<pre class="brush:csharp">
struct PersonStruct
{
    private int id;
    private int milesTraveled;
    public int Id
    {
        get { return id; }
        set { id = value; }
    }
    public string Name { get; private set; }
    private static int InstanceCount;

    public PersonStruct(int id) : this(id, string.Empty) { }

    public PersonStruct(int id, string name) : this()
    {
        Id = id;
        Name = name;
        InstanceCount++;
    }

    public char this[int index]
    {
        get { return Name[index]; }
    }

    private void Walk(int miles)
    {
        milesTraveled += miles;
    }

    private static void IncreaseInstanceCount()
    {
        InstanceCount++;
    }

    private static int GetInstanceCount()
    {
        return InstanceCount;
    }

    public static void Swap(ref int i, ref int j)
    {
        int tmp = i;
        i = j;
        j = tmp;
    }
}
</pre>
<pre class="brush:csharp">
class Program
{
    static void Main()
    {
        // Load a type reflectively, just to look like real-life scenario
        var types = new[]
                        {
                            Assembly.GetExecutingAssembly().GetType(&quot;FasterflectSample.PersonClass&quot;),
                            Assembly.GetExecutingAssembly().GetType(&quot;FasterflectSample.PersonStruct&quot;)
                        };
        Array.ForEach(types, type =&gt;
                                 {
                                     ExecuteNormalApi(type);
                                     ExecuteCacheApi(type);
                                 });
    }

    private static void ExecuteNormalApi(Type type)
    {
        bool isStruct = type.IsValueType;

        // Person.InstanceCount should be 0 since no instance is created yet
        AssertTrue(type.GetField&lt;int&gt;(&quot;InstanceCount&quot;) == 0);

        // Invokes the no-arg constructor
        object obj = type.Construct();

        // Double-check if the constructor is invoked successfully or not
        AssertTrue(null != obj);

        // struct's no-arg constructor cannot be overriden, thus the following checking
        // is not applicable to struct type
        if (!isStruct)
        {
            // Now, Person.InstanceCount should be 1
            AssertTrue(1 == type.GetField&lt;int&gt;(&quot;InstanceCount&quot;));

            // What if we don't know the type of InstanceCount?
            // Just specify object as the type parameter
            AssertTrue(type.GetField&lt;object&gt;(&quot;InstanceCount&quot;) != null);
        }

        // We can bypass the constructor to change the value of Person.InstanceCount
        type.SetField(&quot;InstanceCount&quot;, 2);
        AssertTrue(2 == type.GetField&lt;int&gt;(&quot;InstanceCount&quot;));

        // Let's invoke Person.IncreaseCounter() static method to increase the counter
        // In fact, let's chain the calls to increase 2 times
        type.Invoke(&quot;IncreaseInstanceCount&quot;)
            .Invoke(&quot;IncreaseInstanceCount&quot;);
        AssertTrue(4 == type.GetField&lt;int&gt;(&quot;InstanceCount&quot;));

        // Now, let's retrieve Person.InstanceCount via the static method GetInstanceCount
        AssertTrue(4 == type.Invoke&lt;int&gt;(&quot;GetInstanceCount&quot;));

        // If we're not interested in the return (e.g. only in the side effect),
        // we don't have to specify the type parameter (and can chain the result).
        AssertTrue(4 == type.Invoke(&quot;GetInstanceCount&quot;)
                            .Invoke(&quot;GetInstanceCount&quot;)
                            .Invoke&lt;int&gt;(&quot;GetInstanceCount&quot;));

        // Invoke method receiving ref/out params, we need to put arguments in an array
        var arguments = new object[] { 1, 2 };
        type.Invoke(&quot;Swap&quot;,
            // Parameter types must be set to the appropriate ref type
            new[] { typeof(int).MakeByRefType(), typeof(int).MakeByRefType() },
            arguments);
        AssertTrue(2 == (int)arguments[0]);
        AssertTrue(1 == (int)arguments[1]);

        // Now, invoke the 2-arg constructor.  We don't even have to specify parameter types
        // if we know that the arguments are not null (Fasterflect will internally retrieve type info).
        obj = type.Construct(1, &quot;Doe&quot;);

        // Due to struct type's pass-by-value nature, in order for struct to be used
        // properly with Fasterflect, you need to convert it into a holder (wrapper) first.
        // The call below does nothing if obj is reference type so when unsure, just call it.
        obj = obj.CreateHolderIfValueType();

        // id and name should have been set properly
        AssertTrue(1 == obj.GetField&lt;int&gt;(&quot;id&quot;));
        AssertTrue(&quot;Doe&quot; == obj.GetProperty&lt;string&gt;(&quot;Name&quot;));

        // Let's use the indexer to retrieve the character at index 1
        AssertTrue('o' == obj.GetIndexer&lt;char&gt;(1));

        // If there's null argument, or when we're unsure whether there's a null argument
        // we must explicitly specify the param type array
        obj = type.Construct(new[] { typeof(int), typeof(string) }, new object[] { 1, null })
            .CreateHolderIfValueType();

        // id and name should have been set properly
        AssertTrue(1 == obj.GetField&lt;int&gt;(&quot;id&quot;));
        AssertTrue(null == obj.GetProperty&lt;string&gt;(&quot;Name&quot;));

        // Now, modify the id
        obj.SetField(&quot;id&quot;, 2);
        AssertTrue(2 == obj.GetField&lt;int&gt;(&quot;id&quot;));
        AssertTrue(2 == obj.GetProperty&lt;int&gt;(&quot;Id&quot;));

        // We can chain calls
        obj.SetField(&quot;id&quot;, 3).SetProperty(&quot;Name&quot;, &quot;Buu&quot;);
        AssertTrue(3 == obj.GetProperty&lt;int&gt;(&quot;Id&quot;));
        AssertTrue(&quot;Buu&quot; == obj.GetProperty&lt;string&gt;(&quot;Name&quot;));

        // How about modifying both properties at the same time using an anonymous sample
        obj.SetProperties(new {
                                  Id = 4,
                                  Name = &quot;Nguyen&quot;
                              });
        AssertTrue(4 == obj.GetProperty&lt;int&gt;(&quot;Id&quot;));
        AssertTrue(&quot;Nguyen&quot; == obj.GetProperty&lt;string&gt;(&quot;Name&quot;));

        // Let's have the folk walk 6 miles (and try chaining again)
        obj.Invoke(&quot;Walk&quot;, 1).Invoke(&quot;Walk&quot;, 2).Invoke(&quot;Walk&quot;, 3);

        // Double-check the current value of the milesTravelled field
        AssertTrue(6 == obj.GetField&lt;int&gt;(&quot;milesTraveled&quot;));

        // Construct an array of 10 elements for current type
        var arr = type.MakeArrayType().Construct(10);

        // Get &amp; set element of array
        obj = type.Construct();
        arr.SetElement(4, obj).SetElement(9, obj);

        if (isStruct) // struct, won't have same reference
        {
            AssertTrue(obj.Equals(arr.GetElement&lt;object&gt;(4)));
            AssertTrue(obj.Equals(arr.GetElement&lt;object&gt;(9)));
        }
        else
        {
            AssertTrue(obj == arr.GetElement&lt;object&gt;(4));
            AssertTrue(obj == arr.GetElement&lt;object&gt;(9));
        }

        // Remember, struct array doesn't have null element
        // (instead always initialized to default struct)
        if (!isStruct)
        {
            AssertTrue(null == arr.GetElement&lt;object&gt;(0));
        }
    }

    private static void ExecuteCacheApi(Type type)
    {
        var range = Enumerable.Range(0, 10).ToList();

        // Let's cache the getter for InstanceCount
        StaticAttributeGetter count = type.DelegateForGetStaticField(&quot;InstanceCount&quot;);

        // Now cache the 2-arg constructor of Person and playaround with the delegate returned
        int currentInstanceCount = (int)count();
        ConstructorInvoker ctor = type.DelegateForConstruct(new[] { typeof(int), typeof(string) });
        range.ForEach(i =&gt;
        {
            object obj = ctor(i, &quot;_&quot; + i).CreateHolderIfValueType();
            AssertTrue(++currentInstanceCount == (int)count());
            AssertTrue(i == obj.GetField&lt;int&gt;(&quot;id&quot;));
            AssertTrue(&quot;_&quot; + i == obj.GetProperty&lt;string&gt;(&quot;Name&quot;));
        });

        // Whatever thing we can do with the normal API, we can do with the cache API.
        // For example:
        AttributeSetter nameSetter = type.DelegateForSetProperty(&quot;Name&quot;);
        AttributeGetter nameGetter = type.DelegateForGetProperty(&quot;Name&quot;);

        object person = ctor(1, &quot;Buu&quot;).CreateHolderIfValueType();
        AssertTrue(&quot;Buu&quot; == nameGetter(person));
        nameSetter(person, &quot;Doe&quot;);
        AssertTrue(&quot;Doe&quot; == nameGetter(person));

        // Another example
        person = type.Construct().CreateHolderIfValueType();
        MethodInvoker walk = type.DelegateForInvoke(&quot;Walk&quot;, new[] { typeof(int) });
        range.ForEach(i =&gt; walk(person, i));
        AssertTrue(range.Sum() == person.GetField&lt;int&gt;(&quot;milesTraveled&quot;));
    }

    public static void AssertTrue(bool expression)
    {
        if (!expression)
            throw new Exception(&quot;Not true&quot;);
        Console.WriteLine(&quot;Ok!&quot;);
    }
}
</pre>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fwww.buunguyen.net%2Fblog%2Fnet-reflection-made-fast-simple-fasterflect-1-1-release.html&amp;linkname=.NET%20Reflection%20Made%20Fast%20%26%23038%3B%20Simple%20%26%238211%3B%20Fasterflect%201.1%20Release"><img src="http://www.buunguyen.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a><div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=YOj95rNdyu0:YUZIwjTuQo0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=YOj95rNdyu0:YUZIwjTuQo0:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=YOj95rNdyu0:YUZIwjTuQo0:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/BuuNguyensBlog?a=YOj95rNdyu0:YUZIwjTuQo0:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/BuuNguyensBlog?i=YOj95rNdyu0:YUZIwjTuQo0:D7DqB2pKExk" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://www.buunguyen.net/blog/net-reflection-made-fast-simple-fasterflect-1-1-release.html</feedburner:origLink></item>
	</channel>
</rss>
