<?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:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" version="2.0"><channel><title>Dave's Box</title><link>http://davesbox.com/default.aspx</link><description>&lt;a href="http://davesbox.com"&gt;&lt;img src="/images/transparent.gif" width="531" height="112" border="0" alt="" /&gt;&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2008 (Build: 30417.1769)</generator><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/DavesBox" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="davesbox" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">DavesBox</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item><title>Long Paths in .NET</title><link>http://davesbox.com/archive/2010/03/30/long-paths-in-net.aspx</link><pubDate>Tue, 30 Mar 2010 21:49:32 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:4336</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=4336</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=4336</wfw:comment><comments>http://davesbox.com/archive/2010/03/30/long-paths-in-net.aspx#comments</comments><description>&lt;p&gt;For those that followed the &lt;a href="http://blogs.msdn.com/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx"&gt;Long Path in .NET series&lt;/a&gt; that &lt;a href="http://channel9.msdn.com/shows/Going+Deep/Kim-Hamilton-and-Wes-Dyer-Inside-NET-Rx-and-IObservableIObserver-in-the-BCL-VS-2010/"&gt;Kim Hamilton&lt;/a&gt; wrote a while back, you will be pleased to know that we just released a library over on CodePlex that adds Long Path support to .NET. This project is one of four new experimental projects + source that we released on our &lt;a href="http://blogs.msdn.com/bclteam/archive/2010/03/30/bcl-codeplex-site-launch.aspx"&gt;new BCL CodePlex site&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;a href="http://bcl.codeplex.com/wikipage?title=BigRational&amp;amp;referringTitle=Home"&gt;BigRational&lt;/a&gt;       &lt;br /&gt;BigRational builds on the &lt;a href="http://msdn.microsoft.com/en-us/library/system.numerics.biginteger(VS.100).aspx"&gt;BigInteger&lt;/a&gt; introduced in .NET Framework 4 to create an arbitrary-precision rational number class.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://bcl.codeplex.com/wikipage?title=Long%20Path&amp;amp;referringTitle=Home"&gt;Long Path&lt;/a&gt;       &lt;br /&gt;This library provides functionality to make it easier to work with paths that are longer than the current 259 character limit.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://bcl.codeplex.com/wikipage?title=PerfMonitor&amp;amp;referringTitle=Home"&gt;PerfMoniter&lt;/a&gt;       &lt;br /&gt;PerfMonitor is a command-line tool for profiling the system using Event Tracing for Windows (ETW). PerfMonitor is built on top of the TraceEvent library.&lt;/p&gt;    &lt;p&gt;&lt;a href="http://bcl.codeplex.com/wikipage?title=TraceEvent&amp;amp;referringTitle=Home"&gt;TraceEvent&lt;/a&gt;       &lt;br /&gt;An experimental library that greatly simplifies reading Event Tracing for Windows (ETW) events.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Expect to see a lot more of these experimental libraries in the future from the BCL. Play around with them and &lt;a href="http://bcl.codeplex.com/Thread/List.aspx"&gt;tell us what you think&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=4336" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=uD0yVk9FPVQ:AUQYegHiAsw:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=uD0yVk9FPVQ:AUQYegHiAsw:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/Releases/default.aspx">Releases</category><category domain="http://davesbox.com/archive/tags/BCL/default.aspx">BCL</category><category domain="http://davesbox.com/archive/tags/System.IO/default.aspx">System.IO</category></item><item><title>Maximum number static fields allowed in mscorlib?</title><link>http://davesbox.com/archive/2010/03/04/maximum-number-of-allowed-static-fields-in-mscorlib.aspx</link><pubDate>Thu, 04 Mar 2010 19:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:4326</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=4326</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=4326</wfw:comment><comments>http://davesbox.com/archive/2010/03/04/maximum-number-of-allowed-static-fields-in-mscorlib.aspx#comments</comments><description>&lt;p&gt;The maximum number of static fields allowed in mscorlib? &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;1020&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Yep you read that right, an arbitrary 1020, not even a computer-scientisty power-of-2, like 1024. Static fields are scoped per AppDomain and this limitation is hardcoded in the native implementation of that class. Check out the Rotor source if you are interested (search for &lt;a&gt;STATIC_OBJECT_TABLE_BUCKET_SIZE&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://www.koders.com/cpp/fidAB5740F9B25DA384CA2941A2FB32848143A61888.aspx"&gt;sscli20\sscli20\clr\src\vm\AppDomain.cpp&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Have a guess how a colleague of mine, &lt;a href="http://blogs.msdn.com/bclteam/archive/2004/10/12/241434.aspx"&gt;Brian Grunkemeyer&lt;/a&gt;, found this out today&amp;hellip;&lt;/p&gt;
&lt;p&gt;(This limitation is only in mscorlib &amp;ndash; other assemblies do not have a limitation, or rather, have an insanely high limit that you should never hit)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=4326" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=qTUCV3GrFB0:v58UU3sgdw0:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=qTUCV3GrFB0:v58UU3sgdw0:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description></item><item><title>Type.FullName returning null in the wrong situations?</title><link>http://davesbox.com/archive/2009/08/21/type-fullname-returning-null-in-the-wrong-situations.aspx</link><pubDate>Fri, 21 Aug 2009 14:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:4237</guid><dc:creator>David Kean</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=4237</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=4237</wfw:comment><comments>http://davesbox.com/archive/2009/08/21/type-fullname-returning-null-in-the-wrong-situations.aspx#comments</comments><description>&lt;p&gt;Haibo Luo &lt;a href="http://blogs.msdn.com/haibo_luo/archive/2006/02/17/534480.aspx"&gt;explained way back in 2006&lt;/a&gt; the reasoning behind why &lt;strong&gt;Type.FullName&lt;/strong&gt; and &lt;strong&gt;Type.AssemblyQualifiedName&lt;/strong&gt; return null in certain situations. My reaction was one of surprise when I first encountered this, but it soon made sense once I read the documentation. The workaround, if all you want is a string representation of the type (strictly for display purposes only), is to call &lt;strong&gt;Type.ToString().&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Recently I’ve been working on a feature for a future version of the Framework which is making use of a lot Reflection, in particular these properties. Unfortunately, I came across a couple of situations where these return null when they really shouldn’t. &lt;/p&gt;  &lt;p&gt;The following shows this with an single dimensional array of &lt;strong&gt;Action&amp;lt;T&amp;gt;&lt;/strong&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type = &lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt;.GetType(&lt;span style="color:#a31515;"&gt;&amp;quot;System.Action`1[]&amp;quot;&lt;/span&gt;);

&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Type.FullName: &amp;quot; &lt;/span&gt;+ (type.FullName ?? &lt;span style="color:#a31515;"&gt;&amp;quot;null&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Which outputs:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;Type.FullName: null&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now remember, if you read Haibo’s post above, you would know that &lt;strong&gt;Type.FullName&lt;/strong&gt; returns null when it cannot guarantee that &lt;strong&gt;Type.GetType&lt;/strong&gt; can resolve the same type. Clearly, however, in this situation &lt;strong&gt;Type.GetType&lt;/strong&gt;&amp;#160;&lt;em&gt;can&lt;/em&gt; round trip the result – as it what was what we used to get the Type in the first place! If you try pointers and references to a generic type definition, such as &lt;em&gt;‘Action`1*’&lt;/em&gt; and ‘&lt;em&gt;Action`1&amp;amp;’&lt;/em&gt;, you’ll notice the same issue.&lt;/p&gt;

&lt;p&gt;Okay, so what’s the reason behind this? Well it turns out that the way Reflection decides whether its going to return null or not, is by doing something similar to:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public string &lt;/span&gt;FullName
{
    &lt;span style="color:blue;"&gt;get
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!IsGenericTypeDefinition &amp;amp;&amp;amp; ContainsGenericParameters)
        {
            &lt;span style="color:blue;"&gt;return null&lt;/span&gt;;
        }

        &lt;span style="color:blue;"&gt;return &lt;/span&gt;GetRealFullName();
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Now with the above type, an &lt;strong&gt;Action&amp;lt;T&amp;gt;[]&lt;/strong&gt; isn’t actually a generic definition itself, only its element, &lt;strong&gt;Action&amp;lt;T&amp;gt;&lt;/strong&gt;, is. It is however, considered as having unresolved generic parameters, indicated by &lt;strong&gt;ContainsGenericParameters &lt;/strong&gt;(which &lt;em&gt;does&lt;/em&gt; walk into elements)&lt;strong&gt;. &lt;/strong&gt;Hence why the property takes the the null path.&lt;/p&gt;

&lt;p&gt;Now the question that Reflection really should be asking instead of the &lt;strong&gt;IsGenericTypeDefinition&lt;/strong&gt; check, is; &lt;em&gt;‘am I &lt;u&gt;or any of my elements&lt;/u&gt; a generic definition?’&lt;/em&gt;, but because generic definitions can’t have element types, can be simply shortened to &lt;em&gt;‘am I or my root element a generic definition?’ &lt;/em&gt;Once, we’ve got the right question, we can now come up with a workaround.&lt;/p&gt;

&lt;p&gt;Okay, first we need a way to figure out our root element:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private static &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;GetRootElementType(&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type)
{
    &lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;elementType = type;
    &lt;span style="color:blue;"&gt;while &lt;/span&gt;(elementType.HasElementType)
    {
        elementType = elementType.GetElementType();
    }

    &lt;span style="color:blue;"&gt;return &lt;/span&gt;elementType;
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Once we can figure out that, the rest is pretty straightforward:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;private static string &lt;/span&gt;GetFullName(&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type)
{
    &lt;span style="color:blue;"&gt;string &lt;/span&gt;name = type.FullName;
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(name != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
        &lt;span style="color:blue;"&gt;return &lt;/span&gt;name;

    &lt;span style="color:green;"&gt;// Okay, Reflection&amp;#39;s just told us that it can&amp;#39;t 
    // uniquely identify this type, let us try
    &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;elementType = GetRootElementType(type);
    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!elementType.IsGenericTypeDefinition)
        &lt;span style="color:blue;"&gt;return null&lt;/span&gt;; &lt;span style="color:green;"&gt;// Nope :(

    &lt;/span&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(elementType.DeclaringType != &lt;span style="color:blue;"&gt;null&lt;/span&gt;)
    {   &lt;span style="color:green;"&gt;// Handle nested classes

        &lt;/span&gt;&lt;span style="color:blue;"&gt;return &lt;/span&gt;GetFullName(elementType.DeclaringType) + &lt;span style="color:#a31515;"&gt;&amp;quot;+&amp;quot; &lt;/span&gt;+ type.Name;
    }

    &lt;span style="color:blue;"&gt;return &lt;/span&gt;type.Namespace + &lt;span style="color:#a31515;"&gt;&amp;quot;.&amp;quot; &lt;/span&gt;+ type.Name;
}&lt;/pre&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;

&lt;p&gt;Note, &lt;strong&gt;Type.Name&lt;/strong&gt; does most of the work for us – it already includes any modifiers such as arrays ([]), pointers (*) and references (&amp;amp;). We also need to make sure that we handle nested types. 

  &lt;br /&gt;&lt;/p&gt;

&lt;p&gt;Now let’s try the original code again using our new method:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type = &lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt;.GetType(&lt;span style="color:#a31515;"&gt;&amp;quot;System.Action`1[]&amp;quot;&lt;/span&gt;);

&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Type.FullName: &amp;quot; &lt;/span&gt;+ (GetFullName(type) ?? &lt;span style="color:#a31515;"&gt;&amp;quot;null&amp;quot;&lt;/span&gt;));&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Running, outputs:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;Type.FullName: System.Action`1[]&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Looks good. Now for the ultimate test, the round trip:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type1 = &lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt;.GetType(&lt;span style="color:#a31515;"&gt;&amp;quot;System.Action`1[]&amp;quot;&lt;/span&gt;);

&lt;span style="color:#2b91af;"&gt;Type &lt;/span&gt;type2 = &lt;span style="color:#2b91af;"&gt;Type&lt;/span&gt;.GetType(GetFullName(type1));

&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Same type? &amp;quot; &lt;/span&gt;+ (type1 == type2));&lt;/pre&gt;
  &lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/blockquote&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;Which in turn outputs:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="code"&gt;Same Type? True&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Beautiful. And there we have it – a quick any easy way to work around this. Note, although I’ve sent through through a few different types through this, I’ve haven&amp;#39;t extensively tested it, so your results may vary. I’ll also leave it up to the reader to come up with a similar fix for &lt;strong&gt;Type.AssemblyQualifiedName&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ve already pinged the Reflection guys about this, and hopefully we’ll see a fix in a future Framework version.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=4237" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=mRZC8smB0kw:wchFgITNbTs:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=mRZC8smB0kw:wchFgITNbTs:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/Bugs/default.aspx">Bugs</category><category domain="http://davesbox.com/archive/tags/reflection/default.aspx">reflection</category></item><item><title>Favorite improvement of Visual Studio 2010 so far…</title><link>http://davesbox.com/archive/2009/08/17/favorite-improvement-of-visual-studio-2010-so-far.aspx</link><pubDate>Mon, 17 Aug 2009 16:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:4229</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=4229</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=4229</wfw:comment><comments>http://davesbox.com/archive/2009/08/17/favorite-improvement-of-visual-studio-2010-so-far.aspx#comments</comments><description>&lt;table cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td&gt;
&lt;p&gt;My most favorite improvement in Visual Studio 2010 so far is&amp;hellip;accidently mousing over the &lt;em&gt;Toolbox&lt;/em&gt; tool window for the first time now only takes 5 seconds before you gain control of Visual Studio, rather than the 30+ seconds it took in Visual Studio 2008. &lt;/p&gt;
&lt;p&gt;I heard on the grape vine that they did a bunch of perf work around improving this exact scenario. Now if they could just spend some time on that pesky&amp;nbsp;&lt;em&gt;Add References&lt;/em&gt; dialog&amp;hellip;&lt;/p&gt;
&lt;/td&gt;
&lt;td&gt;&lt;a href="http://davesbox.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/blog/image6_5F00_1011441E.png"&gt;&lt;img height="202" width="235" src="http://davesbox.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/blog/image6_5F00_thumb_5F00_0FA51129.png" alt="image" border="0" title="image" style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" /&gt;&lt;/a&gt; &lt;/td&gt;
&lt;/tr&gt;

&lt;/table&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=4229" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=fBdn3bIgm2k:eM_FqqV5ZOk:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=fBdn3bIgm2k:eM_FqqV5ZOk:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item><item><title>ExpressionVisitor shipping in .NET 4.0</title><link>http://davesbox.com/archive/2009/08/14/expressionvisitor-shipping-in-net-4-0.aspx</link><pubDate>Fri, 14 Aug 2009 16:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:4019</guid><dc:creator>David Kean</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=4019</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=4019</wfw:comment><comments>http://davesbox.com/archive/2009/08/14/expressionvisitor-shipping-in-net-4-0.aspx#comments</comments><description>&lt;p&gt;As an update to &lt;a href="http://davesbox.com/archive/2008/12/09/quot-i-can-t-believe-microsoft-didn-t-make-enter-api-name-here-public-quot.aspx"&gt;“I can’t believe Microsoft didn’t make [Enter API Name Here] public”&lt;/a&gt;, the Visual Studio Languages team (which own the System.Linq namespace as well as the C#, VB and F# compilers) have added a new public version of &lt;a href="http://davesbox.com/archive/2008/12/09/quot-i-can-t-believe-microsoft-didn-t-make-enter-api-name-here-public-quot.aspx"&gt;ExpressionVisitor&lt;/a&gt;. &lt;/p&gt;  &lt;p&gt;This type allows you to traverse an entire expression graph by simply passing the expression to &lt;strong&gt;ExpressionVisitor.Visit(Expression)&lt;/strong&gt;. Each expression type has an associated &lt;strong&gt;VisitXXX&lt;/strong&gt; method (such as &lt;strong&gt;VisitMember(MemberExpression),&lt;/strong&gt; &lt;strong&gt;VisitCatchBlock(CatchBlock)&lt;/strong&gt;, etc) that you can override to get called back every time one of these expressions is encountered.&lt;/p&gt;  &lt;p&gt;This should make &lt;a href="http://codebetter.com/blogs/jeremy.miller/archive/2008/12/04/i-love-ayende-and-oss.aspx"&gt;Jeremy&lt;/a&gt; and &lt;a href="http://ayende.com/"&gt;Oren&lt;/a&gt; very happy. ;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=4019" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=UBdrTCJ3lKI:4BhuUrVTRno:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=UBdrTCJ3lKI:4BhuUrVTRno:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://davesbox.com/archive/tags/Linq/default.aspx">Linq</category></item><item><title>CCI - the new open-source metadata reader</title><link>http://davesbox.com/archive/2009/04/15/cci-the-new-open-source-metadata-reader.aspx</link><pubDate>Wed, 15 Apr 2009 07:44:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:2726</guid><dc:creator>David Kean</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=2726</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=2726</wfw:comment><comments>http://davesbox.com/archive/2009/04/15/cci-the-new-open-source-metadata-reader.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://blogs.msdn.com/hermanventer/"&gt;Herman Ventor&lt;/a&gt;, the brains behind FxCop&amp;#39;s assembly metadata reader, has just released the next version as an &lt;a href="http://ccimetadata.codeplex.com/"&gt;open-source project&lt;/a&gt; over on CodePlex. &lt;/p&gt;
&lt;p&gt;The Common Compiler Infrastructure (CCI) is a set of components for reading and writing CLR assemblies and was developed as an alternative to Reflection. This is an amazing project and if you&amp;#39;ve ever been frustrated by the limitations of Reflection and Reflection Emit - I would highly recommend downloading and checking it out.&lt;/p&gt;
&lt;p&gt;Find out more at: &lt;a href="http://ccimetadata.codeplex.com/"&gt;http://ccimetadata.codeplex.com/&lt;/a&gt; &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=2726" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=C0ynV7IoX1U:RrYYfG4wluU:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=C0ynV7IoX1U:RrYYfG4wluU:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/FxCop/default.aspx">FxCop</category><category domain="http://davesbox.com/archive/tags/cci/default.aspx">cci</category><category domain="http://davesbox.com/archive/tags/reflection/default.aspx">reflection</category></item><item><title>You learn something new every day</title><link>http://davesbox.com/archive/2009/03/06/you-learn-something-new-every-day.aspx</link><pubDate>Fri, 06 Mar 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1944</guid><dc:creator>David Kean</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1944</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1944</wfw:comment><comments>http://davesbox.com/archive/2009/03/06/you-learn-something-new-every-day.aspx#comments</comments><description>&lt;p&gt;I’ve been writing C# code since one of the early betas back in 2001, yet I’ve never run across the following:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;error CS1638: &amp;#39;ToString_WithCache__ShouldReturnICompositionElementDisplayName&amp;#39; is a reserved identifier and cannot be used when ISO language version mode is used.&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I was weirded out by this and thought ‘that’s a hell of a coincidence that the C# compiler has an identifier called ‘ToString_WithCache__ShouldReturnICompositionElementDisplayName’, but as it turns out &lt;a href="http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf"&gt;identifiers with two consecutive underscore’s are actually reserved&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Identifiers containing two consecutive underscore characters (U+005F) are reserved for use by the implementation; however, no diagnostic is required if such an identifier is defined. [Note: For example, an implementation might provide extended keywords that begin with two underscores. end note]&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;You learn something new (however useless) everyday.&lt;/p&gt;  &lt;p&gt;(To see this warning you’ll need to turn on ISO-1 in the Language Version drop down in the Advanced build settings)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1944" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=o9O7H6SUlGs:vh682qyw8Vc:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=o9O7H6SUlGs:vh682qyw8Vc:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/C_2300_/default.aspx">C#</category></item><item><title>Do we need both Visual Basic and C#?</title><link>http://davesbox.com/archive/2009/02/22/do-we-need-both-visual-basic-and-c.aspx</link><pubDate>Sun, 22 Feb 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1680</guid><dc:creator>David Kean</dc:creator><slash:comments>16</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1680</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1680</wfw:comment><comments>http://davesbox.com/archive/2009/02/22/do-we-need-both-visual-basic-and-c.aspx#comments</comments><description>&lt;p&gt;I was reading &lt;a href="http://code.msdn.microsoft.com/vbfuture/Release/ProjectReleases.aspx?ReleaseId=1699"&gt;what was new for Visual Basic 10&lt;/a&gt; over on the VB Futures site, when I came across the following statement:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Overall Visual Basic 10.0 and C# 4.0 will have the closest feature parity at any point in the history of the languages, which will greatly benefit .NET developers who do work in both.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This statement refers to the language changes coming in Visual Studio 2010, such as Visual Basic getting some C#-like features, such as multiline lambdas, auto-implemented properties and implicit line continuation, and C# getting some Visual Basic-like features, such as late binding, implicit pass-by-ref and optional parameters.&lt;/p&gt;  &lt;p&gt;I’m disappointment that the language teams feel the need to have what they call ‘co-evolution’, where any new features in one language also get added to the other. Is there any point Microsoft investing in two separate languages, if they do &lt;u&gt;exactly&lt;/u&gt; the same thing? &lt;/p&gt;  &lt;p&gt;In my opinion (which does not represent Microsoft’s), we would better off adding C-style macros to one of the languages, allowing us to #define the syntax differences between the two languages, and then kill off the other.&lt;/p&gt;  &lt;p&gt;What do others think? Should Microsoft continue to support two (what are) basically the same languages, or should they attempt to differentiate them like they have done with F#?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1680" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=IEgiuW8X31w:35xGIYIruLY:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=IEgiuW8X31w:35xGIYIruLY:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category><category domain="http://davesbox.com/archive/tags/Visual+Studio+2010/default.aspx">Visual Studio 2010</category></item><item><title>Make sure you use the tools at your disposal</title><link>http://davesbox.com/archive/2009/02/19/make-sure-you-use-the-tools-at-your-disposal.aspx</link><pubDate>Thu, 19 Feb 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1653</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1653</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1653</wfw:comment><comments>http://davesbox.com/archive/2009/02/19/make-sure-you-use-the-tools-at-your-disposal.aspx#comments</comments><description>&lt;p&gt;I ran across something interesting on an internal alias about a new marketing campaign on the &lt;a href="http://www.microsoft.com/visualstudio/en-us/products/teamsystem/default.mspx"&gt;Visual Studio Team System marketing site&lt;/a&gt; that allows you to customize an amusing video that you can send to friends and team members. What caught my eye wasn’t the video itself, but the error that some users were encountering when attempting to view one of the Silverlight-based videos:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Message: Unhandled Error in Silverlight 2 Application [Format_InvalidString]      &lt;br /&gt;Arguments:&lt;/p&gt;    &lt;p&gt;Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See &lt;a href="http://go.microsoft.com/fwlink/?linkid=106663&amp;amp;Version=2.0.31005.0&amp;amp;File=mscorlib.dll&amp;amp;Key=Format_InvalidString"&gt;http://go.microsoft.com/fwlink/?linkid=106663&amp;amp;Version=2.0.31005.0&amp;amp;File=mscorlib.dll&amp;amp;Key=Format_InvalidString&lt;/a&gt;&amp;#160;&amp;#160; at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer&amp;amp; number, NumberFormatInfo info, Boolean parseDecimal)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Double.Parse(String s, NumberStyles style, NumberFormatInfo info)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Double.Parse(String s, IFormatProvider provider)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Convert.ToDouble(String value)       &lt;br /&gt;&amp;#160;&amp;#160; at PepTalk_Full.DataObjects.doTextOverlay..ctor(XElement element)       &lt;br /&gt;&amp;#160;&amp;#160; at PepTalk_Full.DataObjects.doPepTalk.Init()       &lt;br /&gt;&amp;#160;&amp;#160; at PepTalk_Full.DataObjects.doPepTalk..ctor()       &lt;br /&gt;&amp;#160;&amp;#160; at PepTalk_Full.App.wc_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Net.WebClient.OnDownloadStringCompleted(DownloadStringCompletedEventArgs e)       &lt;br /&gt;&amp;#160;&amp;#160; at System.Net.WebClient.DownloadStringOperationCompleted(Object arg)&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To keep download sizes smaller, the client Silverlight plug-in does not contain Exception error messages, but by clicking the URL above, or by looking at the stack can you guess what the problem is? I’ll give you a hint – Convert.ToDouble(String) passes &lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.currentculture.aspx"&gt;CultureInfo.CurrentCulture&lt;/a&gt; as the IFormatProvider argument to Double.Parse.&lt;/p&gt;  &lt;p&gt;Yep, you guessed it, basically, the application is attempting to parse a string that it has downloaded from the web and the call to Convert.ToDouble is failing because it is expecting the format of the string to match the current culture, while the string itself is formatted using another culture. For example, the string likely contains a value formatted using the invariant culture, say &lt;em&gt;‘1.00’&lt;/em&gt;, but when a visitor from Germany or Norway comes to visit, Convert.ToDouble(String) is looking for a string in the format ‘&lt;em&gt;1&lt;strong&gt;,&lt;/strong&gt;00’&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;The irony in all this is that if the Microsoft team or contractor that wrote the Silverlight application were actually using the Code Analysis feature of Team System, they would have received the following warning from &lt;a href="http://msdn.microsoft.com/en-us/library/ms182190.aspx"&gt;Specify IFormatProvider&lt;/a&gt;:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;i&gt;Because the behavior of &amp;#39;Convert.ToDouble(string)&amp;#39; could vary based on the current user&amp;#39;s locale settings, replace this call in &amp;#39;doTextOverlay.doTextOverlay(XElement)&amp;#39; with a call to &amp;#39;Convert.ToDouble(string, IFormatProvider)&amp;#39;. If the result of &amp;#39;Convert.ToDouble(string, IFormatProvider)&amp;#39; will be displayed to the user, specify &amp;#39;CultureInfo.CurrentCulture&amp;#39; as the &amp;#39;IFormatProvider&amp;#39; parameter. Otherwise, if the result will be stored and accessed by software, such as when it is persisted to disk or to a database, specify &amp;#39;CultureInfo.InvariantCulture&amp;#39;.&lt;/i&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;All the developer has to do is to call the overload of Convert.ToDouble that takes an IFormatProvider passing it CultureInfo.InvariantCulture and the application would work on all systems regardless of the user’s culture.&lt;/p&gt;  &lt;p&gt;The moral of the story is, use the tools available at your disposal – if you have Team System, use Code Analysis, otherwise, we still offer &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=9AEAA970-F281-4FB0-ABA1-D59D7ED09772"&gt;FxCop&lt;/a&gt; as a free download – they both catch bugs like this one.     &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1653" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=V8Khq8H-YYE:zVCZFrbC5e8:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=V8Khq8H-YYE:zVCZFrbC5e8:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/FxCop/default.aspx">FxCop</category><category domain="http://davesbox.com/archive/tags/Bugs/default.aspx">Bugs</category></item><item><title>Code Camp Oz 2009</title><link>http://davesbox.com/archive/2009/02/16/code-camp-oz-2009.aspx</link><pubDate>Mon, 16 Feb 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1568</guid><dc:creator>David Kean</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1568</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1568</wfw:comment><comments>http://davesbox.com/archive/2009/02/16/code-camp-oz-2009.aspx#comments</comments><description>&lt;p&gt;I’m speaking at &lt;a href="http://www.codecampoz.com/"&gt;Code Camp Oz 2009&lt;/a&gt; on April 4th in Wagga Wagga, Australia. I’ll be giving a talk called ‘A lap around the Managed Extensibility Framework’, in which I’ll give a run through of the major features of MEF.&lt;/p&gt;  &lt;p&gt;Mitch Denny has also announced the rest of the &lt;a href="http://notgartner.wordpress.com/2009/02/15/code-camp-oz-2009-speakers-sessions-announced/"&gt;speakers &amp;amp; sessions&lt;/a&gt;, which looks like a great line up this year. I had the pleasure of attending the first one in 2005 when I was last in Australia and it’s not only a great (and free) way to learn more about current and new technologies, but is also a great place to network with peers.&lt;/p&gt;  &lt;p&gt;It’s free and run over the weekend of April 4th/5th. &lt;a href="http://codecampoz2009.eventbrite.com/"&gt;Sign up&lt;/a&gt; today.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1568" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=0Qwnq7cq6Ok:4Wkm74Kuwi4:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=0Qwnq7cq6Ok:4Wkm74Kuwi4:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/MEF/default.aspx">MEF</category></item><item><title>Changing default creation policy from shared (singleton) to non-shared (transient)</title><link>http://davesbox.com/archive/2009/02/07/changing-default-creation-policy-from-shared-singleton-to-non-shared-transient.aspx</link><pubDate>Sat, 07 Feb 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1412</guid><dc:creator>David Kean</dc:creator><slash:comments>1</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1412</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1412</wfw:comment><comments>http://davesbox.com/archive/2009/02/07/changing-default-creation-policy-from-shared-singleton-to-non-shared-transient.aspx#comments</comments><description>&lt;p&gt;One of the things that you might run across when starting to work with MEF, is that by default, all parts are created as singleton (&amp;lsquo;shared&amp;rsquo;) instances.&lt;/p&gt;
&lt;p&gt;For example, given the following part:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;Export&lt;/span&gt;]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyView
&lt;/span&gt;{
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;Running the following code:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;&lt;span style="color:#2b91af;"&gt;TypeCatalog &lt;/span&gt;catalog = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TypeCatalog&lt;/span&gt;(&lt;span style="color:blue;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;MyView&lt;/span&gt;));
&lt;span style="color:#2b91af;"&gt;CompositionContainer &lt;/span&gt;container = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;CompositionContainer&lt;/span&gt;(catalog);

&lt;span style="color:blue;"&gt;var &lt;/span&gt;view1 = container.GetExportedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;MyView&lt;/span&gt;&amp;gt;();
&lt;span style="color:blue;"&gt;var &lt;/span&gt;view2 = container.GetExportedObject&amp;lt;&lt;span style="color:#2b91af;"&gt;MyView&lt;/span&gt;&amp;gt;();

&lt;span style="color:#2b91af;"&gt;Console&lt;/span&gt;.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;Are same object? &amp;quot; &lt;/span&gt;+ (view1 == view2));&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Outputs:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;Are same object? True&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In certain scenarios, such as web applications, you typically want the reverse, that is, a new instance (&amp;lsquo;non-shared&amp;rsquo;) of a part created on every request. &lt;/p&gt;
&lt;p&gt;We allow you to indicate that, using the &lt;strong&gt;CompositionOptionsAttribute:&lt;/strong&gt; &lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;[&lt;span style="color:#2b91af;"&gt;Export&lt;/span&gt;]
[&lt;span style="color:#2b91af;"&gt;CompositionOptions&lt;/span&gt;(CreationPolicy=&lt;span style="color:#2b91af;"&gt;CreationPolicy&lt;/span&gt;.NonShared)]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyView
&lt;/span&gt;{
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Unfortunately, if you have a lot of them, this can be a bit of a hassle to do this for every part. As luck would have it, the latest drop of MEF allows you modify the default with a little bit of code:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;TransientCompositionContainer &lt;/span&gt;: &lt;span style="color:#2b91af;"&gt;CompositionContainer
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;TransientCompositionContainer(&lt;span style="color:#2b91af;"&gt;ComposablePartCatalog &lt;/span&gt;catalog)
        : &lt;span style="color:blue;"&gt;base&lt;/span&gt;(catalog)
    {
    }

    &lt;span style="color:blue;"&gt;protected override &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:#2b91af;"&gt;Export&lt;/span&gt;&amp;gt; GetExportsCore(&lt;span style="color:#2b91af;"&gt;ImportDefinition &lt;/span&gt;definition)
    {
        definition = AdaptDefinition(definition);
        
        &lt;span style="color:blue;"&gt;return base&lt;/span&gt;.GetExportsCore(definition);
    }

    &lt;span style="color:blue;"&gt;private &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ImportDefinition &lt;/span&gt;AdaptDefinition(&lt;span style="color:#2b91af;"&gt;ImportDefinition &lt;/span&gt;definition)
    {
        &lt;span style="color:#2b91af;"&gt;ContractBasedImportDefinition &lt;/span&gt;namedDefinition = definition &lt;span style="color:blue;"&gt;as &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ContractBasedImportDefinition&lt;/span&gt;;
        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(namedDefinition != &lt;span style="color:blue;"&gt;null &lt;/span&gt;&amp;amp;&amp;amp; namedDefinition.RequiredCreationPolicy == &lt;span style="color:#2b91af;"&gt;CreationPolicy&lt;/span&gt;.Any)
        {   &lt;span style="color:green;"&gt;// Only change the creation policy if the importer/requester did not specify one
 
            &lt;/span&gt;definition = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ContractBasedImportDefinition&lt;/span&gt;(namedDefinition.ContractName,
                                                           namedDefinition.RequiredMetadata,
                                                           namedDefinition.Cardinality,
                                                           namedDefinition.IsRecomposable,
                                                           namedDefinition.IsPrerequisite,
                                                           &lt;span style="color:#2b91af;"&gt;CreationPolicy&lt;/span&gt;.NonShared);
        }

        &lt;span style="color:blue;"&gt;return &lt;/span&gt;definition;
    }
}&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;Basically what is happening above is that all requests to the container are routed through GetExportsCore. When we see a request (represented as an ImportDefinition) that states that it does not have a preference for a particular creation policy (which is the default when querying from the container, or when using the [Import] attribute), we create a new request that explicitly specifies that it wants a non-shared instance and route that back to the base.&lt;/p&gt;
&lt;p&gt;Running the above sample, substituting the standard container with the transient container, should now output:&lt;/p&gt;
&lt;blockquote&gt;
&lt;pre class="code"&gt;Are same object? False&lt;/pre&gt;
&lt;/blockquote&gt;
&lt;p&gt;There we have it &amp;ndash; a container that defaults to non-shared parts. You can download the container below.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1412" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=rJ3XT9nqg8k:UiUDJVZRRp4:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=rJ3XT9nqg8k:UiUDJVZRRp4:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><enclosure url="http://davesbox.com/cfs-file.ashx/__key/CommunityServer.Components.PostAttachments/00.00.00.14.12/TransientCompositionContainer_2E00_cs" length="1706" type="text/plain" /><category domain="http://davesbox.com/archive/tags/MEF/default.aspx">MEF</category></item><item><title>New Managed Extensibility Framework drop</title><link>http://davesbox.com/archive/2009/01/27/new-managed-extensibility-framework-drop.aspx</link><pubDate>Tue, 27 Jan 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1299</guid><dc:creator>David Kean</dc:creator><slash:comments>4</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1299</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1299</wfw:comment><comments>http://davesbox.com/archive/2009/01/27/new-managed-extensibility-framework-drop.aspx#comments</comments><description>&lt;p&gt;We’ve &lt;a href="http://www.codeplex.com/MEF/Release/ProjectReleases.aspx?ReleaseId=22313"&gt;dropped another version of the Managed Extensibility Framework&lt;/a&gt; over on our CodePlex site.&lt;/p&gt;  &lt;p&gt;Changes since the last drop:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Diagnostics improvement.&lt;/strong&gt; We now provide a lot more information in error messages when something goes wrong with composition. We’ve also made the main types look a lot better under the debugger. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Lifetime/Creation Policy&lt;/strong&gt;. Importers can now request a specific creation policy (ie shared or non-shared) for an injected object if they so want. Non-disposable non-shared objects can now be GC’d before the container is disposed (before it used to hold onto them indefinitely). &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Ripped &lt;/strong&gt;&lt;a href="http://davesbox.com/archive/2008/06/21/binding-private-and-internal-members-using-the-compositioncontainer.aspx"&gt;&lt;strong&gt;AllowNonPublicCompositionAttribute&lt;/strong&gt;&lt;/a&gt;. We now always inject private and internal members. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Namespace cleanup.&lt;/strong&gt; We’ve added a couple of sub namespaces under System.ComponentModel.Composition, called ‘Hosting’ and ‘Primitives’. Hosting contains types commonly used only by host applications, such as ExportProvider, CompositionContainer and the catalogs. Primitives contains types for implementing a custom programming model, such as ComposablePart, ImportDefinition and ExportDefinition. &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Type name cleanup&lt;/strong&gt;. Gone are the hideously long type names; AttributedAssemblyPartCatalog, AttributedTypesPartCatalog, AggregratingComposablePartCatalog, and in their place; AssemblyCatalog, TypeCatalog and AggregateCatalog. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Check it out, and &lt;a href="http://www.codeplex.com/MEF/Thread/List.aspx"&gt;tell us what you think&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1299" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=JdDb--Zi6iM:YNVS1PEyfpQ:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=JdDb--Zi6iM:YNVS1PEyfpQ:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/MEF/default.aspx">MEF</category><category domain="http://davesbox.com/archive/tags/Releases/default.aspx">Releases</category></item><item><title>API Hall of Shame #2 – Useless Exception Messages</title><link>http://davesbox.com/archive/2009/01/02/api-hall-of-shame-2-useless-exception-messages.aspx</link><pubDate>Fri, 02 Jan 2009 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1111</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1111</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1111</wfw:comment><comments>http://davesbox.com/archive/2009/01/02/api-hall-of-shame-2-useless-exception-messages.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.reflection.reflectiontypeloadexception.aspx"&gt;ReflectionTypeLoadException&lt;/a&gt; takes the cake with this message:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This is one of the most frustrating messages to encounter &lt;em&gt;outside&lt;/em&gt; of the debugger. What do you think the first thing you are going to do when you hit this in production?….Exactly, look at the LoaderExceptions property, which is impossible without forethought or a debugger.&lt;/p&gt;  &lt;p&gt;How could have the loader team improved the usability of this exception ten-fold? By simply outputting the first couple of entries from the property:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Unable to load one or more of the requested types. The first few exceptions are provided below. Retrieve the LoaderException property for more information.       &lt;br /&gt;---&amp;gt; Could not load file or assembly ‘Library, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8e9c13fee402ae29&amp;#39; or one of its dependencies. Strong name validation failed.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Much better. Straight away the user can see the root cause of the problem and can react without needing to attach a debugger.&lt;/p&gt;  &lt;p&gt;(As a side note, CompositionException in &lt;a href="http://www.codeplex.com/MEF"&gt;MEF&lt;/a&gt; &lt;a href="http://davesbox.com/archive/2008/06/15/getting-more-information-from-the-compositionexception.aspx"&gt;used to suffer from the same problem&lt;/a&gt; when I first arrived on the team; luckily, our &lt;a href="http://www.codeplex.com/MEF"&gt;latest release&lt;/a&gt; fixes this)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1111" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=V-sbYgXjYhw:TKMs5zhk7Ig:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=V-sbYgXjYhw:TKMs5zhk7Ig:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/API+Hall+of+Shame/default.aspx">API Hall of Shame</category><category domain="http://davesbox.com/archive/tags/API+Design/default.aspx">API Design</category></item><item><title>Documenting ‘undocumented’ features</title><link>http://davesbox.com/archive/2008/12/29/documenting-undocumented-features.aspx</link><pubDate>Mon, 29 Dec 2008 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1099</guid><dc:creator>David Kean</dc:creator><slash:comments>2</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1099</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1099</wfw:comment><comments>http://davesbox.com/archive/2008/12/29/documenting-undocumented-features.aspx#comments</comments><description>&lt;p&gt;MMayerl &lt;a href="http://msdn.microsoft.com/en-us/library/x53a06bb.aspx#CommunityContent"&gt;asks over on the MSDN wiki&lt;/a&gt;,&amp;nbsp;why we don&amp;rsquo;t document the undocumented C# keywords &lt;em&gt;&lt;strong&gt;__makeref&lt;/strong&gt;&lt;/em&gt;, &lt;em&gt;&lt;strong&gt;__reftype&lt;/strong&gt;&lt;/em&gt;, &lt;strong&gt;__&lt;em&gt;refvalue&lt;/em&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;em&gt;__arglist&lt;/em&gt;&lt;/strong&gt;?&lt;/p&gt;
&lt;p&gt;Because that defeats of the purpose of them being undocumented.&lt;/p&gt;
&lt;p&gt;They are undocumented for a reason; so that the C# team is free to change and remove these keywords without worrying whether customers have taken dependencies on them. Documenting them conveys an implicit support agreement between Microsoft and the user, thereby preventing the team from ever changing the keywords. &lt;/p&gt;
&lt;p&gt;We want less people to use them, not more.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1099" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=6USVvPgo9R8:6XE86oRqOGw:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=6USVvPgo9R8:6XE86oRqOGw:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://davesbox.com/archive/tags/Compatibility/default.aspx">Compatibility</category></item><item><title>Code Analysis failing with ‘Invalid settings passed to CodeAnalysis task’</title><link>http://davesbox.com/archive/2008/12/26/code-analysis-failing-with-invalid-settings-passed-to-codeanalysis-task.aspx</link><pubDate>Fri, 26 Dec 2008 15:00:00 GMT</pubDate><guid isPermaLink="false">2122c344-89bc-4cd7-b145-b0515ba3439f:1097</guid><dc:creator>David Kean</dc:creator><slash:comments>0</slash:comments><wfw:commentRss>http://davesbox.com/rsscomments.aspx?PostID=1097</wfw:commentRss><wfw:comment>http://davesbox.com/commentapi.aspx?PostID=1097</wfw:comment><comments>http://davesbox.com/archive/2008/12/26/code-analysis-failing-with-invalid-settings-passed-to-codeanalysis-task.aspx#comments</comments><description>&lt;p&gt;I’ve seen recent reports of Visual Studio Code Analysis failing (such as &lt;a href="http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/3a626e7a-c144-4f39-9dc7-54cb129fae04/"&gt;this one&lt;/a&gt;) with the following error:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Invalid settings passed to CodeAnalysis task.&amp;#160; See output window for details.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Looking in the output window will show something similar to:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Switch &amp;#39;/targetframeworkversion&amp;#39; is an unknown switch.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;As &lt;a href="http://davesbox.com/archive/2008/08/25/new-for-visual-studio-2008-sp1-and-fxcop-1-36-multi-targeting-rule.aspx"&gt;I’ve mentioned earlier&lt;/a&gt;, the &lt;em&gt;/targetframeworkversion&lt;/em&gt; switch was added in Visual Studio 2008 SP1 to support the new multi-targeting rule. The fact that the FxCop does not understand the switch, is a big indicator that something went astray with the installation of the service pack.&lt;/p&gt;  &lt;p&gt;Luckily the fix is rather easy, simple &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=FBEE1648-7106-44A7-9649-6D9F6D58056E&amp;amp;displaylang=en"&gt;re-install it&lt;/a&gt;.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://davesbox.com/aggbug.aspx?PostID=1097" width="1" height="1"&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/DavesBox?a=8ROXHqj-8Vg:hfivP_lmANk:D7DqB2pKExk"&gt;&lt;img src="http://feeds.feedburner.com/~ff/DavesBox?i=8ROXHqj-8Vg:hfivP_lmANk:D7DqB2pKExk" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;</description><category domain="http://davesbox.com/archive/tags/FxCop/default.aspx">FxCop</category><category domain="http://davesbox.com/archive/tags/Bugs/default.aspx">Bugs</category></item></channel></rss>

