<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><title type="html">עומר.נט</title><subtitle type="html">כי עברית שפה יפה</subtitle><id>http://blogs.microsoft.co.il/blogs/omer/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/" /><link rel="self" type="application/atom+xml" href="http://blogs.microsoft.co.il/blogs/omer/atom.aspx" /><generator uri="http://communityserver.org" version="3.1.20917.1142">Community Server</generator><updated>2008-10-14T17:14:01Z</updated><entry><title>This Blog Has Moved</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2011/10/10/913400.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2011/10/10/913400.aspx</id><published>2011-10-10T13:55:00Z</published><updated>2011-10-10T13:55:00Z</updated><content type="html">&lt;p&gt;Please find its new home at &lt;a href="http://omervk.wordpress.com"&gt;omervk.wordpress.com&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;The blog has been made read-only, but will not be deleted for now.  All of the content has been replicated to the new blog, so you can continue the discussion on the older posts there.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I would like to thank weblogs.asp.net for being my home these past few years.&lt;/p&gt;&lt;p&gt;Omer &lt;br /&gt;&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=913400" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author></entry><entry><title>The Anti-Social Network</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2009/11/17/446894.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2009/11/17/446894.aspx</id><published>2009-11-17T15:59:00Z</published><updated>2009-11-17T15:59:00Z</updated><content type="html">&lt;p&gt;(I’ve returned from my trip a few months ago, but didn’t have enough to blog about; hopefully, this is my returning to a semi-regular posting schedule; also, I’ve decided to veer off .NET in some of my posts, focusing on more issues that I like to talk about and offer my opinions on)&lt;/p&gt;  &lt;p&gt;(&lt;strong&gt;Update&lt;/strong&gt;: This article is now &lt;a href="http://www.holesinthenet.co.il/archives/6359"&gt;featured in Hebrew&lt;/a&gt; in Gal Mor’s blog “Holes in the Net”)&lt;/p&gt;  &lt;p&gt;&lt;a title="CC-BY-NC, Min Jung Kim" href="http://www.flickr.com/photos/minjung/4077749710/"&gt;&lt;img style="border-right-width:0px;margin:5px 0px 5px 10px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="CC-BY-NC, Min Jung Kim" border="0" alt="CC-BY-NC, Min Jung Kim" align="right" src="http://weblogs.asp.net/blogs/okloeten/image_47AFFAB1.png" width="289" height="334" /&gt;&lt;/a&gt; Social networks have been flourishing in the past few years, and have let us reach more people than we could before them. I, personally, use both Facebook and Twitter on a daily basis. The trend of &lt;em&gt;‘socialized’&lt;/em&gt; applications is steadily marching on. A simple example of that is e-commerce sites looking to increase their conversion rate with you using recommendations from your friends.&lt;/p&gt;  &lt;p&gt;However, there is yet another trend coming up that we should worry about, which is users trying to force anti-social behavior. Here are a couple of examples:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Calibri"&gt;Facebook introduced the ‘Like’ feature in February 2009, making it easier for users to say that they like a certain something: a post, a picture, a link, etc. This feature was immediately put to good use, with people ‘liking’&lt;/font&gt;&lt;font face="Calibri"&gt; things, instead of creating long comment chains. ‘Liking’ something was much easier, too, being a single-click action, and increased the amount of participation. &lt;strong&gt;The Like feature was a good thing&lt;/strong&gt;.         &lt;br /&gt;&lt;/font&gt;&lt;font face="Calibri"&gt;       &lt;br /&gt;Lately, voices have come up in favor of &lt;strong&gt;creating a ‘Dislike’ button&lt;/strong&gt;. Users feel that since they have an easy way to notify their friend that they like his or her post, that they should equally be able to notify them of not liking it, &lt;strong&gt;discouraging the person&lt;/strong&gt; from continuing this kind of activity.         &lt;br /&gt;        &lt;br /&gt;To use the ‘Dislike’ feature would be like saying to someone’s face that their joke was not funny or that they are ugly. Face to face, you might only do that to your closest friends and family and even then in jest, but &lt;strong&gt;online it’s much easier to be anti-social&lt;/strong&gt;. The socially acceptable alternative to the ‘Dislike’ button would be to ‘Hide’ that friend’s updates, which unlike ignoring someone in the real world, is something the friend will never know about and will therefore never get offended by.         &lt;br /&gt;&lt;/font&gt;&lt;/li&gt;    &lt;li&gt;&lt;font face="Calibri"&gt;The way to use Twitter is not something users can agree on. One thing that is widely agreed upon, though, is that &lt;strong&gt;following someone means you care what they say&lt;/strong&gt;. That leads most people to the mistaken belief that the more followers you acquire, the more people will believe you are important and influential.         &lt;br /&gt;        &lt;br /&gt;One of the ways in which users are attempting to inflate their follower count is the contemptible habit of expecting &lt;strong&gt;auto-follow-back&lt;/strong&gt;. This means that the user follows you, waits for you to follow them back and then un-follows you if you haven’t. This widely embraced practice causes unsuspecting users to be barraged with a very large number of follow notifications from people, brands and companies they have no interest in.         &lt;br /&gt;        &lt;br /&gt;This is downright adamant to spam, which we can all agree is one of the least socially acceptable activities you can partake in online. &lt;/font&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;These examples just go to show the trend of &lt;strong&gt;users wanting to add anti-social behavior&lt;/strong&gt; to a social platform.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Social networks&lt;/strong&gt;, on their part, &lt;strong&gt;should never allow themselves to be catalysts for anti-social behavior&lt;/strong&gt;. Anti-social activities, such as hiding users or reporting them or their actions should remain hidden from all other users and must remain in confidence between the user and the platform. The real world parallel to this would be ‘telling on’ someone, which is frowned upon.     &lt;br /&gt;Facebook tries to avoid that by making all positive social activities more open, while keeping the anti-social activities on a one-on-one basis between the user and the platform. Unfavorable comments are still prevalent, but are unavoidable.     &lt;br /&gt;Twitter is, on the other hand, lagging far behind by keeping their network very much bare of personal filters (no way to hide unwanted tweets) and allowing users to easily find out who un-followed them, to name just a few issues.&lt;/p&gt;  &lt;p&gt;The rule-of-thumb I present here does not stop with social networks, but continues to other socially-influenced platforms. Socially-enabled games follow this rule too: &lt;strong&gt;FarmVille&lt;/strong&gt;, which at the time of writing of this post is the most popular and fastest growing game of all time on Facebook, does the same.     &lt;br /&gt;Players have a &lt;strong&gt;multitude of socially-positive activities to choose from&lt;/strong&gt;, such as sending each other gifts, taking in animals their friends put up for adoption, helping out on friends’ farms and even racing each other to the top of their local hall of fame in the long run. On the other hand, &lt;strong&gt;there are no socially-negative activities&lt;/strong&gt; in the game: players can not steal crops or animals from friends, mess up their farms, etc.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Social platforms should make it easy to broadcast socially-positive activities&lt;/strong&gt; and hard to broadcast the negative ones. Once they follow this simple frame of mind, they will &lt;strong&gt;reap the psychological and sociological benefits&lt;/strong&gt;.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=446894" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="2 ⅛s" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/2+_5B21_s/default.aspx" /><category term="Karma" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Karma/default.aspx" /><category term="Social" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Social/default.aspx" /></entry><entry><title>Hiatus</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2009/02/23/234546.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2009/02/23/234546.aspx</id><published>2009-02-23T12:48:45Z</published><updated>2009-02-23T12:48:45Z</updated><content type="html">&lt;p&gt;&lt;a href="http://www.flickr.com/photos/omervk/1166629131/in/set-72157601542639193/"&gt;&lt;img title="" style="border-right:0px;border-top:0px;display:inline;margin:0px 0px 0px 10px;border-left:0px;border-bottom:0px;" height="240" alt="" src="http://weblogs.asp.net/blogs/okloeten/image_14AD2338.png" width="215" align="right" border="0" /&gt;&lt;/a&gt; In 15 days’ time, I’ll be taking off on a four months long trip around the world. I’ll be hiking and travelling my way through Japan (March-May), the United States of America (May-July) and the Netherlands (July). I’ve been planning this trip for a long time now, since I came back from Japan for the first time in August 2007 (the photo on the right was taken near the Tsurugaoka Hachiman-gu Shrine in &lt;a href="http://wikitravel.org/en/Kamakura"&gt;Kamakura&lt;/a&gt;), and have taken a long leave from work to accomplish it. What this means is that from March 10th you can expect a long pause in my semi-regular updates.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;I am not dead&lt;/strong&gt; :)&lt;/p&gt;  &lt;p&gt;If you’re a reader who lives along my path and want to meet up for a beer and a lively chat, ping me via the &lt;a href="http://weblogs.asp.net/okloeten/contact.aspx"&gt;contact form&lt;/a&gt;. I’ll be reading my emails every once in a while, so don’t worry if you only get an answer after a few days.&lt;/p&gt;  &lt;p&gt;If you want to read about my trip, I’ll be posting regular updates to my &lt;a href="http://blog.omervk.com/"&gt;new travel blog&lt;/a&gt;.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=234546" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="Personal" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Personal/default.aspx" /></entry><entry><title>Circumventing the KB957543 .NET 3.5 SP1 Regression Bug</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/29/218810.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/29/218810.aspx</id><published>2009-01-29T16:23:18Z</published><updated>2009-01-29T16:23:18Z</updated><content type="html">&lt;p&gt;A couple of days ago I hit a regression bug in .NET 3.5 SP1, in which when you have a generic class that implements ISerializable and has static variables – you can not serialize it using a BinaryFormatter without your application either hanging (x86) or raising an exception (x64 – a TargetInvocationException containing an OutOfMemoryException). This only happens if you use a reference type as a generic argument.&lt;/p&gt;  &lt;p&gt;It’s already &lt;a href="http://www.hanselman.com/blog/UpdateOnNETFramework35SP1AndWindowsUpdate.aspx"&gt;well known&lt;/a&gt;, but I have yet to find a workaround documented anywhere. You could simply install the &lt;a href="http://code.msdn.microsoft.com/KB957543"&gt;hotfix&lt;/a&gt;, but well, I wouldn’t if I were you – it hasn’t been thoroughly tested yet. Moreover, you might not even be able to do so due to either internal politics, strict IT rules or the fact that you simply do not have control over the hosting server.&lt;/p&gt;  &lt;p&gt;Let’s take the simplest class that causes the issue:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color:#2b91af;"&gt;Serializable&lt;/span&gt;]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private static int &lt;/span&gt;list = 0;

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color:blue;"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;When using the class as such:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;MemoryStream &lt;/span&gt;stream = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MemoryStream&lt;/span&gt;())
{
    &lt;span style="color:#2b91af;"&gt;BinaryFormatter &lt;/span&gt;formatter = &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;BinaryFormatter&lt;/span&gt;();
    formatter.Serialize(stream, &lt;span style="color:blue;"&gt;new &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;());
    stream.Position = 0;
    &lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; item = (&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt;)formatter.Deserialize(stream);
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The last line will hit the bug.&lt;/p&gt;

&lt;p&gt;To work around this issue, simply move your static variables into a new subclass:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color:#2b91af;"&gt;Serializable&lt;/span&gt;]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private static class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;KB957543
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public static int &lt;/span&gt;list = 0;
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color:blue;"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can still access all of your static variables and you don’t hit the bug.&lt;/p&gt;

&lt;p&gt;Note that when you use anonymous methods or lambdas, they are cached as static variables of the type, meaning that you will have to manually type all of your lambdas.&lt;/p&gt;

&lt;p&gt;Here’s an example of such a type that is prone to the bug:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color:#2b91af;"&gt;Serializable&lt;/span&gt;]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color:blue;"&gt;public static string &lt;/span&gt;Concat(&lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt; numbers)
    {
        &lt;span style="color:blue;"&gt;return string&lt;/span&gt;.Join(&lt;span style="color:#a31515;"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;, numbers.Select(i =&amp;gt; i.ToString()).ToArray());
    }

    &lt;span style="color:blue;"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If we look through Reflector, we can see that there is a cached delegate in our type:&lt;/p&gt;

&lt;p&gt;&lt;img title="" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;border-right-width:0px;" height="186" alt="" src="http://weblogs.asp.net/blogs/okloeten/image_292AD855.png" width="589" border="0" /&gt; &lt;/p&gt;

&lt;p&gt;Since this is a static member, it makes the type susceptible to the bug and we now need to manually create the cached member ourselves:&lt;/p&gt;

&lt;pre class="code"&gt;&lt;code&gt;[&lt;span style="color:#2b91af;"&gt;Serializable&lt;/span&gt;]
&lt;span style="color:blue;"&gt;public class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;MyClass&lt;/span&gt;&amp;lt;T&amp;gt; : &lt;span style="color:#2b91af;"&gt;ISerializable
&lt;/span&gt;{
    &lt;span style="color:blue;"&gt;private static class &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;KB957543
    &lt;/span&gt;{
        &lt;span style="color:blue;"&gt;public static readonly &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;Func&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;, &lt;span style="color:blue;"&gt;string&lt;/span&gt;&amp;gt; ToString = i =&amp;gt; i.ToString();
    }

    &lt;span style="color:blue;"&gt;public &lt;/span&gt;MyClass()
    {
    }

    &lt;span style="color:blue;"&gt;public static string &lt;/span&gt;Concat(&lt;span style="color:#2b91af;"&gt;IEnumerable&lt;/span&gt;&amp;lt;&lt;span style="color:blue;"&gt;int&lt;/span&gt;&amp;gt; numbers)
    {
        &lt;span style="color:blue;"&gt;return string&lt;/span&gt;.Join(&lt;span style="color:#a31515;"&gt;&amp;quot;, &amp;quot;&lt;/span&gt;, numbers.Select(&lt;span style="color:#2b91af;"&gt;KB957543&lt;/span&gt;.ToString).ToArray());
    }

    &lt;span style="color:blue;"&gt;protected &lt;/span&gt;MyClass(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }

    &lt;span style="color:blue;"&gt;void &lt;/span&gt;&lt;span style="color:#2b91af;"&gt;ISerializable&lt;/span&gt;.GetObjectData(&lt;span style="color:#2b91af;"&gt;SerializationInfo &lt;/span&gt;info, &lt;span style="color:#2b91af;"&gt;StreamingContext &lt;/span&gt;context)
    {
    }
}&lt;/code&gt;&lt;/pre&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=218810" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="Advices" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Advices/default.aspx" /><category term="How To" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/How+To/default.aspx" /><category term=".NET" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/.NET/default.aspx" /></entry><entry><title>Let SQL Server Tell You Which Indexes to Rebuild</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/05/206425.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/05/206425.aspx</id><published>2009-01-05T11:37:45Z</published><updated>2009-01-05T11:37:45Z</updated><content type="html">&lt;p&gt;When index fragmentation becomes too high, indexes will be very inefficient. Other than planning a good index design, you should &lt;a href="http://msdn.microsoft.com/library/ms188388.aspx"&gt;rebuild / reorganize your indexes&lt;/a&gt; every once in a while.&lt;/p&gt;  &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;ALTER INDEX [&amp;#39; &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;ix&lt;span style="color:gray;"&gt;.&lt;/span&gt;name &lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;] ON [&amp;#39; &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;s&lt;span style="color:gray;"&gt;.&lt;/span&gt;name &lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;].[&amp;#39; &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;t&lt;span style="color:gray;"&gt;.&lt;/span&gt;name &lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;] &amp;#39; &lt;/span&gt;&lt;span style="color:gray;"&gt;+
       &lt;/span&gt;&lt;span style="color:blue;"&gt;CASE WHEN &lt;/span&gt;ps&lt;span style="color:gray;"&gt;.&lt;/span&gt;avg_fragmentation_in_percent &lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;40 &lt;span style="color:blue;"&gt;THEN &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;REBUILD&amp;#39; &lt;/span&gt;&lt;span style="color:blue;"&gt;ELSE &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;REORGANIZE&amp;#39; &lt;/span&gt;&lt;span style="color:blue;"&gt;END &lt;/span&gt;&lt;span style="color:gray;"&gt;+
       &lt;/span&gt;&lt;span style="color:blue;"&gt;CASE WHEN &lt;/span&gt;pc&lt;span style="color:gray;"&gt;.&lt;/span&gt;partition_count &lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;1 &lt;span style="color:blue;"&gt;THEN &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39; PARTITION = &amp;#39; &lt;/span&gt;&lt;span style="color:gray;"&gt;+ &lt;/span&gt;&lt;span style="color:magenta;"&gt;cast&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;ps&lt;span style="color:gray;"&gt;.&lt;/span&gt;partition_number &lt;span style="color:blue;"&gt;as nvarchar&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;max&lt;/span&gt;&lt;span style="color:gray;"&gt;)) &lt;/span&gt;&lt;span style="color:blue;"&gt;ELSE &lt;/span&gt;&lt;span style="color:red;"&gt;&amp;#39;&amp;#39; &lt;/span&gt;&lt;span style="color:blue;"&gt;END
FROM   &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;indexes &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;ix &lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;tables &lt;/span&gt;t
           &lt;span style="color:blue;"&gt;ON &lt;/span&gt;t&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id &lt;/span&gt;&lt;span style="color:gray;"&gt;= &lt;/span&gt;ix&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id
       &lt;/span&gt;&lt;span style="color:gray;"&gt;INNER JOIN &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;schemas &lt;/span&gt;s
           &lt;span style="color:blue;"&gt;ON &lt;/span&gt;t&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;schema_id &lt;/span&gt;&lt;span style="color:gray;"&gt;= &lt;/span&gt;s&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;schema_id
       &lt;/span&gt;&lt;span style="color:gray;"&gt;INNER JOIN (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;index_id&lt;span style="color:gray;"&gt;, &lt;/span&gt;avg_fragmentation_in_percent&lt;span style="color:gray;"&gt;, &lt;/span&gt;partition_number
                   &lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;dm_db_index_physical_stats &lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:magenta;"&gt;DB_ID&lt;/span&gt;&lt;span style="color:gray;"&gt;(), NULL, NULL, NULL, NULL)) &lt;/span&gt;ps
           &lt;span style="color:blue;"&gt;ON &lt;/span&gt;t&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id &lt;/span&gt;&lt;span style="color:gray;"&gt;= &lt;/span&gt;ps&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id &lt;/span&gt;&lt;span style="color:gray;"&gt;AND &lt;/span&gt;ix&lt;span style="color:gray;"&gt;.&lt;/span&gt;index_id &lt;span style="color:gray;"&gt;= &lt;/span&gt;ps&lt;span style="color:gray;"&gt;.&lt;/span&gt;index_id
       &lt;span style="color:gray;"&gt;INNER JOIN (&lt;/span&gt;&lt;span style="color:blue;"&gt;SELECT &lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;index_id&lt;span style="color:gray;"&gt;, &lt;/span&gt;&lt;span style="color:magenta;"&gt;COUNT&lt;/span&gt;&lt;span style="color:gray;"&gt;(&lt;/span&gt;&lt;span style="color:blue;"&gt;DISTINCT &lt;/span&gt;partition_number&lt;span style="color:gray;"&gt;) &lt;/span&gt;&lt;span style="color:blue;"&gt;AS &lt;/span&gt;partition_count
                   &lt;span style="color:blue;"&gt;FROM &lt;/span&gt;&lt;span style="color:green;"&gt;sys&lt;/span&gt;&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:green;"&gt;partitions
                   &lt;/span&gt;&lt;span style="color:blue;"&gt;GROUP BY &lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id&lt;/span&gt;&lt;span style="color:gray;"&gt;, &lt;/span&gt;index_id&lt;span style="color:gray;"&gt;) &lt;/span&gt;pc
           &lt;span style="color:blue;"&gt;ON &lt;/span&gt;t&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id &lt;/span&gt;&lt;span style="color:gray;"&gt;= &lt;/span&gt;pc&lt;span style="color:gray;"&gt;.&lt;/span&gt;&lt;span style="color:magenta;"&gt;object_id &lt;/span&gt;&lt;span style="color:gray;"&gt;AND &lt;/span&gt;ix&lt;span style="color:gray;"&gt;.&lt;/span&gt;index_id &lt;span style="color:gray;"&gt;= &lt;/span&gt;pc&lt;span style="color:gray;"&gt;.&lt;/span&gt;index_id
&lt;span style="color:blue;"&gt;WHERE  &lt;/span&gt;ps&lt;span style="color:gray;"&gt;.&lt;/span&gt;avg_fragmentation_in_percent &lt;span style="color:gray;"&gt;&amp;gt; &lt;/span&gt;10 &lt;span style="color:gray;"&gt;AND
       &lt;/span&gt;ix&lt;span style="color:gray;"&gt;.&lt;/span&gt;name &lt;span style="color:gray;"&gt;IS NOT NULL
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The above query will give you a list of recommended index rebuild / reorganize &lt;a href="http://msdn.microsoft.com/library/ms188388.aspx"&gt;statements&lt;/a&gt; for your database, according &lt;a href="http://blog.sqlauthority.com/"&gt;Pinal Dave&lt;/a&gt;’s &lt;a href="http://blog.sqlauthority.com/2007/12/22/sql-server-difference-between-index-rebuild-and-index-reorganize-explained-with-t-sql-script/"&gt;10-40 rule&lt;/a&gt;, although you are welcome to tweak it to your liking. It supports non-partitioned as well as partitioned indexes. If you want a more intense check for fragmentation, change the last &lt;code&gt;NULL&lt;/code&gt; in the &lt;code&gt;&lt;a href="http://msdn.microsoft.com/library/ms188917.aspx"&gt;dm_db_index_physical_stats&lt;/a&gt;&lt;/code&gt; call to &amp;#39;SAMPLED&amp;#39; or even &amp;#39;DETAILED&amp;#39; (include quotes).&lt;/p&gt;

&lt;p&gt;It’s a handy little tool for database administrators and saves a lot of the hassle of monitoring index fragmentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Added multi-schema support as suggested by MJ12 and another check for null index names.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=206425" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="SQL Server" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/SQL+Server/default.aspx" /></entry><entry><title>SQL Server Management Studio 2008 IntelliSense Doesn't Recognize Special Characters</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/05/206383.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2009/01/05/206383.aspx</id><published>2009-01-05T09:16:12Z</published><updated>2009-01-05T09:16:12Z</updated><content type="html">&lt;p&gt;&lt;img title="ssms" style="border-top-width:0px;display:inline;border-left-width:0px;border-bottom-width:0px;margin:5px 10px 5px 5px;border-right-width:0px;" height="156" alt="ssms" src="http://weblogs.asp.net/blogs/okloeten/ssms_0C00114E.png" width="286" align="left" border="0" /&gt;&lt;/p&gt;  &lt;p&gt;I just filed &lt;a href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=390749"&gt;a new bug with Microsoft Connect&lt;/a&gt;. I certainly hope this one doesn’t get shrugged off like many of my other bugs did.&lt;/p&gt;  &lt;p&gt;Want to reproduce it yourselves? Just create a table with a character that can only be valid inside the context of brackets (like a comma or braces) and then try to select from it. Don’t keep the CREATE clauses in the same query window or it might just work. See the screenshot below.&lt;/p&gt;  &lt;p&gt;This is very frustrating because this means that not only is there no IntelliSense for these objects, but IntelliSense now gets in the way of actual querying as it will autocomplete incorrect names.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=206383" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="SQL Server" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/SQL+Server/default.aspx" /></entry><entry><title>Adobe AIR and Hebrew Fonts</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/24/200049.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/24/200049.aspx</id><published>2008-12-24T08:07:57Z</published><updated>2008-12-24T08:07:57Z</updated><content type="html">&lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/okloeten/HebrewTwhirl_316513D9.png"&gt;&lt;img title="Twhirl" style="border-right:0px;border-top:0px;display:inline;margin:5px 5px 5px 10px;border-left:0px;border-bottom:0px;" height="202" alt="Twhirl" src="http://weblogs.asp.net/blogs/okloeten/HebrewTwhirl_thumb_7A5B0FD2.png" width="130" align="right" border="0" /&gt;&lt;/a&gt;(I’ve noticed quite a few people were having this problem, so I decided to blog about it. This might have to do with all non-English fonts, but I experienced it only with Hebrew)&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/okloeten/TweetDeckHebrew_557548C6.png"&gt;&lt;img title="TweetDeck" style="border-right:0px;border-top:0px;display:inline;margin:5px 10px 5px 5px;border-left:0px;border-bottom:0px;" height="202" alt="TweetDeck" src="http://weblogs.asp.net/blogs/okloeten/TweetDeckHebrew_thumb_0B2A8E21.png" width="124" align="left" border="0" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The only reason I use Adobe AIR is for the Twitter application &lt;a href="http://www.twhirl.org/project/twhirl" target="_blank"&gt;Twhirl&lt;/a&gt;. However, I noticed the Hebrew text was incorrectly displayed (word order was reversed).&lt;/p&gt;  &lt;p&gt;I did not find a solution for this online and the guys at Twhirl didn’t know what to make of this.&lt;/p&gt;  &lt;p&gt;After toying with a few of the options, I finally found the answer – the fonts used by Twhirl were in Hebrew, but AIR wasn’t playing nicely with them. I switched from Calibri to Tahoma and found that the text was just fine.&lt;/p&gt;  &lt;p&gt;Both &lt;a href="http://twitter.com/effifuks/status/1059151241" target="_blank"&gt;@effifuks&lt;/a&gt; and &lt;a href="http://twitter.com/JonathanRauch/status/1075041688" target="_blank"&gt;@JonathanRauch&lt;/a&gt; (with TweetDeck, where he didn’t see Hebrew text at all – see the left screenshot) experienced the same issue.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=200049" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author></entry><entry><title>MSBuild Script to Compress All JavaScript Files in a Project</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195049.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195049.aspx</id><published>2008-12-18T16:58:47Z</published><updated>2008-12-18T16:58:47Z</updated><content type="html">I’ve got one project in my solution which has a lot of JavaScript files and they keep on coming. We’ve been using the &lt;a href="http://developer.yahoo.com/yui/compressor/" target="_blank"&gt;YUI Compressor&lt;/a&gt; for quite a while and it’s proven an effective tool. After a lot of time of fiddling with the project’s MSBuild script, I came up with the following:   &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Target &lt;/span&gt;&lt;span style="color:red;"&gt;Name&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;BeforeBuild&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;MakeDir&lt;br /&gt;&lt;/span&gt;&lt;span style="color:red;"&gt;    Directories&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;compressed\%(Content.RelativeDir)&lt;/span&gt;&amp;quot;&lt;br /&gt;    &lt;span style="color:red;"&gt;Condition&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;(%(Content.Extension) == &amp;#39;.js&amp;#39;) And (!(Exists(&amp;#39;compressed\%(Content.RelativeDir)&amp;#39;)))&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Exec&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:red;"&gt;Command&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;java -jar yuicompressor-x.y.z.jar --type js -o compressed\%(Content.Identity) %(Content.Identity)&lt;/span&gt;&amp;quot;&lt;br /&gt;    &lt;span style="color:red;"&gt;Condition&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;%(Content.Extension) == &amp;#39;.js&amp;#39;&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;
  &amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;CreateItem&lt;br /&gt;    &lt;/span&gt;&lt;span style="color:red;"&gt;Include&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;compressed\%(Content.Identity)&lt;/span&gt;&amp;quot;&lt;br /&gt;    &lt;span style="color:red;"&gt;Condition&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&amp;quot;&lt;span style="color:blue;"&gt;%(Content.Extension) == &amp;#39;.js&amp;#39;&lt;/span&gt;&amp;quot; &lt;span style="color:blue;"&gt;/&amp;gt;
&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;Target&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;p&gt;The above takes all of the JavaScript files in your project, compresses them (in the same relative directories) into the &lt;em&gt;compressed&lt;/em&gt; directory and then adds them to the project, in case it gets deployed anywhere.&lt;/p&gt;

&lt;p&gt;Note that I’m using the &lt;em&gt;Extension&lt;/em&gt;, &lt;em&gt;Identity&lt;/em&gt; and &lt;em&gt;RelativeDir&lt;/em&gt; &lt;a href="http://msdn.microsoft.com/library/ms164313.aspx" target="_blank"&gt;well-known item metadata attributes&lt;/a&gt; in order to impose batching, since batches causes loops instead of the string concatenation that happens when you reference the items themselves.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=195049" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="JavaScript" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/JavaScript/default.aspx" /><category term="MSBuild" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/MSBuild/default.aspx" /></entry><entry><title>Your Mouth Says Windows-1255, But Your Eyes Say ISO-8859-1</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195038.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195038.aspx</id><published>2008-12-18T16:45:34Z</published><updated>2008-12-18T16:45:34Z</updated><content type="html">&lt;h4&gt;I recently wrote an engine that gets XML files stored at our clients’ servers using HTTP requests. One of our clients decided to serve the XML file with one encoding and encode the file itself with another. This posed a problem to XDocument.&lt;/h4&gt;  &lt;p&gt;The client decided to encode their XML using the Windows-1255 encoding (Hebrew), noting the encoding correctly in the XML’s declaration, but served the file stating the ISO-8859-1 (Latin) encoding. This meant that I couldn’t just use &lt;em&gt;XDocument&lt;/em&gt;’s normal &lt;em&gt;Load&lt;/em&gt; method to load directly from the stream because &lt;strong&gt;XDocument looks at the HTTP headers and takes the document’s encoding from them&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;Here’s a snippet of the code I used to get over that:&lt;/p&gt;  &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;using &lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;HttpWebResponse &lt;/span&gt;response = (&lt;span style="color:#2b91af;"&gt;HttpWebResponse&lt;/span&gt;)request.GetResponse())
{
    &lt;span style="color:green;"&gt;// Use response&amp;#39;s charset.
    &lt;/span&gt;&lt;span style="color:blue;"&gt;var &lt;/span&gt;encoding = &lt;span style="color:#2b91af;"&gt;Encoding&lt;/span&gt;.GetEncoding(&lt;span style="color:#a31515;"&gt;&amp;quot;ISO-8859-1&amp;quot;&lt;/span&gt;);

    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(!&lt;span style="color:blue;"&gt;string&lt;/span&gt;.IsNullOrEmpty(response.CharacterSet))
        encoding = &lt;span style="color:#2b91af;"&gt;Encoding&lt;/span&gt;.GetEncoding(response.CharacterSet);

    &lt;span style="color:blue;"&gt;byte&lt;/span&gt;[] bytes = ReadStream(response.GetResponseStream());

    &lt;span style="color:green;"&gt;// Get the XML with the response&amp;#39;s charset.
    &lt;/span&gt;&lt;span style="color:blue;"&gt;string &lt;/span&gt;xml = &lt;span style="color:blue;"&gt;new string&lt;/span&gt;(encoding.GetChars(bytes));
    &lt;span style="color:blue;"&gt;int &lt;/span&gt;endOfDeclaration = xml.IndexOf(&lt;span style="color:#a31515;"&gt;&amp;quot;?&amp;gt;&amp;quot;&lt;/span&gt;);

    &lt;span style="color:blue;"&gt;if &lt;/span&gt;(endOfDeclaration != -1)
    {
        &lt;span style="color:green;"&gt;// Try to find out the encoding from the declaration.
        &lt;/span&gt;&lt;span style="color:blue;"&gt;string &lt;/span&gt;decl = xml.Substring(0, endOfDeclaration + 2) + &lt;span style="color:#a31515;"&gt;&amp;quot;&amp;lt;duperoot /&amp;gt;&amp;quot;&lt;/span&gt;;
        &lt;span style="color:#2b91af;"&gt;XDocument &lt;/span&gt;declDoc = &lt;span style="color:#2b91af;"&gt;XDocument&lt;/span&gt;.Parse(decl);
        &lt;span style="color:blue;"&gt;var &lt;/span&gt;docEncoding = &lt;span style="color:#2b91af;"&gt;Encoding&lt;/span&gt;.GetEncoding(declDoc.Declaration.Encoding);

        &lt;span style="color:blue;"&gt;if &lt;/span&gt;(docEncoding == encoding)
            &lt;span style="color:blue;"&gt;return &lt;/span&gt;xml;
        &lt;span style="color:blue;"&gt;else
            return new string&lt;/span&gt;(docEncoding.GetChars(bytes));
    }
    &lt;span style="color:blue;"&gt;else
    &lt;/span&gt;{
        &lt;span style="color:green;"&gt;// Not XML or something... Send up.
&lt;/span&gt;    }
}&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;What I did here was to create a new document with the original XML’s declaration (the Latin characters which make up the XML’s declaration always have the same byte position), add a dupe root and parse that to get the name of the encoding used by the document. I then use that encoding to decode the document correctly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note &lt;/strong&gt;that I’m using ISO-8859-1 as the default response’s encoding, since that is what HTTP’s specification demands.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=195038" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="How To" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/How+To/default.aspx" /></entry><entry><title>HTML to JavaScript HTML DOM Converter</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195024.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195024.aspx</id><published>2008-12-18T16:20:46Z</published><updated>2008-12-18T16:20:46Z</updated><content type="html">&lt;p&gt;One of our products demands converting quite a large amount of HTML to equivalent scripts, written in JavaScript that create said HTML. Looking around the Internet, I found no tool that will automate this process for me, so I went ahead and created this simple little application.&lt;/p&gt; &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/okloeten/htmltojsdom_37FDB96F.png"&gt;&lt;img title="htmltojsdom" style="border-top-width:0px;display:block;border-left-width:0px;float:none;border-bottom-width:0px;margin-left:auto;margin-right:auto;border-right-width:0px;" height="603" alt="htmltojsdom" src="http://weblogs.asp.net/blogs/okloeten/htmltojsdom_thumb_3AE2F855.png" width="616" border="0" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;I&amp;#39;ve written it using &lt;a href="http://www.codeplex.com/htmlagilitypack"&gt;HTML Agility Pack&lt;/a&gt; and &lt;a href="http://www.codeproject.com/KB/recipes/CSSParser.aspx"&gt;Simple CSS Parser&lt;/a&gt;. It’s hardly perfect and might incorrectly reference attributes, but I’ve tweaked it long enough for it to work, I’m guessing, 95% of the time.&lt;/p&gt; &lt;p&gt;The source is not yet included (I want to set it up as a project on CodePlex later on), but for now &lt;a href="http://blogs.microsoft.co.il/files/folders/195021/download.aspx" target="_blank"&gt;you can download it from here&lt;/a&gt;.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=195024" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="Tools: Misc" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Tools_3A00_+Misc/default.aspx" /><category term="JavaScript" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/JavaScript/default.aspx" /></entry><entry><title>The Death of System.DateTime?</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195010.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/12/18/195010.aspx</id><published>2008-12-18T15:56:38Z</published><updated>2008-12-18T15:56:38Z</updated><content type="html">&lt;h4&gt;It’s been a few months since I started getting acquainted with the &lt;em&gt;System.DateTimeOffset&lt;/em&gt; type and I can honestly say I don’t see any reason to use &lt;em&gt;System.DateTime&lt;/em&gt; anymore.&lt;/h4&gt;  &lt;p&gt;I’ve even gone as far as ask whether &lt;a href="http://stackoverflow.com/questions/264617/when-would-you-prefer-datetime-over-datetimeoffset" target="_blank"&gt;anyone knew when I would rather use &lt;em&gt;DateTime&lt;/em&gt; over &lt;em&gt;DateTimeOffset&lt;/em&gt;&lt;/a&gt;. The responses I got were along the lines of ‘backwards compatibility’ or ‘when you need an abstract time’. My recommendation is that if you haven’t yet looked at the type, go do it now and after that, start using it.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;So what is this &lt;em&gt;DateTimeOffset&lt;/em&gt;?&lt;/strong&gt; When representing a date/time, especially in an internationally-faced system, you have to include a time-zone. &lt;em&gt;DateTime&lt;/em&gt; did a very poor job handling time-zones, like being insensitive to changes. &lt;em&gt;DateTimeOffset&lt;/em&gt; is the exact same thing as &lt;em&gt;DateTime&lt;/em&gt;, only it takes heed of time-zones. For instance, comparing two &lt;em&gt;DateTimeOffset&lt;/em&gt;s with the same UTC time in different time-zones will result in equality.     &lt;br /&gt;Moreover, &lt;em&gt;DateTime&lt;/em&gt; also had only three modes: &lt;em&gt;Local&lt;/em&gt;, &lt;em&gt;UTC&lt;/em&gt; and &lt;em&gt;Unspecified&lt;/em&gt;, whereas &lt;em&gt;DateTimeOffset&lt;/em&gt; has an &lt;em&gt;Offset&lt;/em&gt; property, allowing you to create dates in any time-zone you like.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Things to note:&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;font face="Calibri"&gt;&lt;em&gt;DateTime&lt;/em&gt; can be implicitly converted to &lt;em&gt;DateTimeOffset&lt;/em&gt;, but not vice-versa. To do that, you would have to use &lt;em&gt;DateTimeOffset’&lt;/em&gt;s &lt;em&gt;DateTime&lt;/em&gt; property.         &lt;br /&gt;When converting this way, the &lt;em&gt;DateTime’&lt;/em&gt;s kind will always be &lt;em&gt;Unspecified&lt;/em&gt;.&lt;/font&gt;       &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:#2b91af;"&gt;DateTimeOffset &lt;/span&gt;dateTimeOffset = &lt;span style="color:#2b91af;"&gt;DateTimeOffset&lt;/span&gt;.UtcNow;
&lt;span style="color:#2b91af;"&gt;DateTime &lt;/span&gt;dateTime = dateTimeOffset.DateTime;&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;font face="Calibri"&gt;When parsing a &lt;em&gt;DateTimeOffset&lt;/em&gt;, note that you can specify &lt;em&gt;AssumeUniversal&lt;/em&gt; and &lt;em&gt;AssumeLocal&lt;/em&gt; using the &lt;em&gt;DateTimeStyles&lt;/em&gt; enum. These come in handy when the string you’re parsing has no time-zone data.&lt;/font&gt; 

    &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;if &lt;/span&gt;(!&lt;span style="color:#2b91af;"&gt;DateTimeOffset&lt;/span&gt;.TryParse(myDateString, &lt;span style="color:#2b91af;"&gt;CultureInfo&lt;/span&gt;.InvariantCulture.DateTimeFormat, &lt;span style="color:#2b91af;"&gt;DateTimeStyles&lt;/span&gt;.AssumeUniversal, &lt;span style="color:blue;"&gt;out &lt;/span&gt;dateTimeOffset))
    dateTimeOffset = &lt;span style="color:blue;"&gt;default&lt;/span&gt;(&lt;span style="color:#2b91af;"&gt;DateTimeOffset&lt;/span&gt;);&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;

  &lt;li&gt;&lt;font face="Calibri"&gt;It is a best practice to store all of your dates as UTC in the database, regardless of the physical location of your users / servers. When doing this, be sure to manually change your &lt;em&gt;DateTimeOffset&lt;/em&gt; objects to UTC using &lt;em&gt;ToUniversalTime&lt;/em&gt; and only then use the &lt;em&gt;DateTime&lt;/em&gt; property as I have previously noted. &lt;/font&gt;

    &lt;pre class="code"&gt;&lt;code&gt;SaveTimeToDatabase(dateTimeOffset.ToUniversalTime().DateTime);&lt;/code&gt;&lt;/pre&gt;
Note that you do not need to convert &lt;em&gt;DateTimeOffset&lt;/em&gt; objects to any time-zone to do calculations / comparisons. The only time you need to convert them to a time-zone is for displaying them to the user.&lt;/font&gt; &lt;/li&gt;

  &lt;li&gt;&lt;font face="Calibri"&gt;If you want to store a user’s time-zone (on a database that doesn’t support date/times with time-zones), it would be best to have a translation table and use the &lt;em&gt;TimeZoneInfo&lt;/em&gt; class’s Ids (for instance: &lt;em&gt;TimeZoneInfo.Local.Id&lt;/em&gt;). Then you could use &lt;em&gt;TimeZoneInfo.FindSystemTimeZoneById&lt;/em&gt; to translate that value to a &lt;em&gt;TimeZoneInfo&lt;/em&gt; and use that object’s &lt;em&gt;BaseUtcOffset &lt;/em&gt;property to get the difference from UTC. 

      &lt;br /&gt;This may seem a bit cumbersome, but considering the fact that time-zones change due to daylight savings time, you can’t just store the difference from UTC and would be better suited allowing Windows to take care of these issues for you. 

      &lt;br /&gt;Here’s a sample of this method of conversion:&lt;/font&gt; 

    &lt;pre class="code"&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;string &lt;/span&gt;id = &lt;span style="color:#a31515;"&gt;&amp;quot;Israel Standard Time&amp;quot;&lt;/span&gt;;
&lt;span style="color:#2b91af;"&gt;DateTimeOffset &lt;/span&gt;utcnow = &lt;span style="color:#2b91af;"&gt;DateTimeOffset&lt;/span&gt;.UtcNow;

&lt;span style="color:#2b91af;"&gt;DateTimeOffset &lt;/span&gt;now = utcnow.ToOffset(&lt;span style="color:#2b91af;"&gt;TimeZoneInfo&lt;/span&gt;.FindSystemTimeZoneById(id).BaseUtcOffset);&lt;/code&gt;&lt;/pre&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Side note:&lt;/strong&gt; When storing these in the database, it would be prudent to use SQL Server 2008’s &lt;em&gt;datetimeoffset&lt;/em&gt; type, which is the equivalent of &lt;em&gt;DateTimeOffset&lt;/em&gt; and takes care of the time-zones in the same manner.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=195010" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="Advices" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/Advices/default.aspx" /></entry><entry><title>ארוחת הבלוגרים השישית - איכות זו לא מילה גסה</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/11/08/163143.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/11/08/163143.aspx</id><published>2008-11-08T12:18:40Z</published><updated>2008-11-08T12:18:40Z</updated><content type="html">&lt;p dir="rtl" align="center"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/omer/WindowsLiveWriter/c44cb52c4b6f_12B19/n572039866_1584350_8616_2.jpg"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:10px 0px;border-right-width:0px;" height="335" alt="אנשים בולסים בשר" src="http://blogs.microsoft.co.il/blogs/omer/WindowsLiveWriter/c44cb52c4b6f_12B19/n572039866_1584350_8616_thumb.jpg" width="504" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;font size="-2"&gt;תמונה: דור רוטמן, צילום: אחד המלצרים&lt;/font&gt;&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;בערב סתיו חביב התכנסו להם כ-15 בלוגרים ישראליים לבליסת בשר אינטנסיבית בחדר פרטי במסעדת &lt;strong&gt;דוריס קצבים&lt;/strong&gt;. כמו שאתם יכולים לראות למעלה, אנשים לא הצליחו להתאפק ואפילו במהלך התמונה המשיכו לאכול.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;בין שיחות על היפה והחנון, JavaScript, בוסים של אנשים מסוימים (אהמ אהמ), העובדה שאני &lt;a href="http://blogs.microsoft.co.il/blogs/bursteg/archive/2008/11/05/developer-academy-3-session-list-first-draft.aspx"&gt;מרצה ב-Developer Academy הבא&lt;/a&gt; וכולם באים (ברור שבאים) ונסיון להבין איך זה שבכל ארוחה מגיע לידיים של יוסי מחשב בתצורה זו או אחרת, אנשים בלסו, שתו ונהנו.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;עוד תמונות אצל &lt;a href="http://www.facebook.com/album.php?aid=67855&amp;amp;id=572039866"&gt;דור&lt;/a&gt; ו&lt;a href="http://www.facebook.com/album.php?aid=44682&amp;amp;id=770254050"&gt;מאיה&lt;/a&gt;.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;נתראה בארוחה הבאה! :) &lt;p dir="rtl" align="right"&gt;ארוחות קודמות:  &lt;ul align="right"&gt; &lt;li&gt; &lt;div dir="rtl" align="right"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/omer/archive/2007/11/28/37893.aspx"&gt;הארוחה החמישית&lt;/a&gt; - 2007-11-27.&lt;/div&gt; &lt;li&gt; &lt;div dir="rtl" align="right"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/omer/archive/2007/02/22/8683.aspx"&gt;הארוחה הרביעית&lt;/a&gt; - 2007-02-21.&lt;/div&gt; &lt;li&gt; &lt;div dir="rtl" align="right"&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/omer/archive/2006/11/21/4739.aspx"&gt;הארוחה השלישית&lt;/a&gt; - 2006-11-20.&lt;/div&gt; &lt;li&gt; &lt;div dir="rtl" align="right"&gt;&lt;a href="http://weblogs.asp.net/okloeten/archive/2004/06/25/166310.aspx"&gt;הארוחה השניה&lt;/a&gt; - 2004-06-24.&lt;/div&gt; &lt;li&gt; &lt;div dir="rtl" align="right"&gt;&lt;a href="http://weblogs.asp.net/rosherove/archive/0001/01/01/128801.aspx"&gt;הארוחה הראשונה&lt;/a&gt; - 2004-05-09.&lt;/div&gt;&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=163143" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="קהילה" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_E705D405D905DC05D405_/default.aspx" /><category term="ארוחת בלוגרים" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D005E805D505D705EA05_+_D105DC05D505D205E805D905DD05_/default.aspx" /><category term="חומר מקורי" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D705D505DE05E805_+_DE05E705D505E805D905_/default.aspx" /></entry><entry><title>תזכורת - ארוחת הבלוגרים השישית - 05/11/2008</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/11/02/160958.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/11/02/160958.aspx</id><published>2008-11-02T02:06:37Z</published><updated>2008-11-02T02:06:37Z</updated><content type="html">&lt;p dir="rtl" align="right"&gt;&lt;a title="&amp;quot;Skirt Steak...just right&amp;quot; by Mike, CC-NC-SA" href="http://flickr.com/photos/anotherpintplease/1572027789/" target="_blank"&gt;&lt;img style="margin:0px 0px 5px 10px;" alt="&amp;quot;Skirt Steak...just right&amp;quot; by Mike, CC-NC-SA" src="http://farm3.static.flickr.com/2260/1572027789_4b2108f31e_m.jpg" align="right" border="0" /&gt;&lt;/a&gt;רק רציתי להזכיר לכולם שארוחת הבלוגרים השישית תהיה ב&lt;strong&gt;יום רביעי השבוע בשעה 18:30&lt;/strong&gt;.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;עד עכשיו אישרו הגעתם קרוב ל-20 איש. נקווה ש&lt;strong&gt;&lt;a href="http://www.doris-k.co.il/index.asp?pct=1&amp;amp;uid=240&amp;amp;id=1467"&gt;דוריס קצבים&lt;/a&gt;&lt;/strong&gt; יוכלו להכיל את ההתרגשות.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;אם עוד לא אמרתם שאתם מגיעים, כדאי שתגידו בין אם בתגובות פה או &lt;a href="http://www.facebook.com/event.php?eid=30664933919"&gt;באירוע בפייסבוק&lt;/a&gt;.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;נתראה ברביעי. בואו רעבים!&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=160958" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="קהילה" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_E705D405D905DC05D405_/default.aspx" /><category term="ארוחת בלוגרים" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D005E805D505D705EA05_+_D105DC05D505D205E805D905DD05_/default.aspx" /><category term="חומר מקורי" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D705D505DE05E805_+_DE05E705D505E805D905_/default.aspx" /></entry><entry><title>My View of C# 4.0</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/10/29/159464.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/10/29/159464.aspx</id><published>2008-10-29T00:16:53Z</published><updated>2008-10-29T00:16:53Z</updated><content type="html">&lt;p&gt;I&amp;#39;ve known a bit about C# 4.0 for a while now and have had time to think about it. I&amp;#39;ve just re-read the &lt;a href="http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=csharpfuture&amp;amp;DownloadId=3550" target="_blank"&gt;New features in C# 4.0&lt;/a&gt; paper published by Microsoft and would like to offer the following critique of the language&amp;#39;s new features:&lt;/p&gt; &lt;h4&gt;Dynamic Lookup&lt;/h4&gt; &lt;p&gt;&lt;a title="Microsoft PDC 2008 by Manohar Dasari, CC-BY" href="http://flickr.com/photos/manohard/2979001570/"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:5px 5px 5px 10px;border-right-width:0px;" height="181" alt="Microsoft PDC 2008 by Manohar Dasari, CC-BY" src="http://weblogs.asp.net/blogs/okloeten/WindowsLiveWriter/MyViewofC4.0_6C/1_3.jpg" width="260" align="right" border="0" /&gt;&lt;/a&gt;This feature just makes me cringe, just like &lt;a href="http://weblogs.asp.net/okloeten/archive/2003/11/01/35097.aspx" target="_blank"&gt;anonymous methods made me cringe&lt;/a&gt; when they were introduced in C# 2.0. To this day, I hardly use them, as they always feel like a kludge to me (lambda expressions fixed that).&lt;br /&gt;The &lt;code&gt;dynamic&lt;/code&gt; keyword is as open to abuse as anything could be. It takes the principles of static typing and throws the baby out with the bathwater.&lt;/p&gt; &lt;h6&gt;&lt;/h6&gt; &lt;h5&gt;What is wrong with it&lt;/h5&gt; &lt;p&gt;When looked at initially, the &lt;code&gt;dynamic&lt;/code&gt; keyword is great, because it simplifies and speeds up what is usually done with Reflection and Primary Interop Assemblies, both in the aspect of development times and the aspect of run time. Unfortunately, too much of a good thing is bad for you. Imagine the following:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;public dynamic&lt;/span&gt; GetCustomer()
{
    &lt;span&gt;// mystery...&lt;/span&gt;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;What do we have here then? I don&amp;#39;t know and neither does IntelliSense? I guess we&amp;#39;ll have to go with trial and error.&lt;br /&gt;I admit this is quite the dramatization, but you get my point: it&amp;#39;s ripe for abusing an otherwise perfectly fine static syntax.&lt;/p&gt;
&lt;p&gt;Moreover, the &lt;code&gt;dynamic&lt;/code&gt; keyword&amp;#39;s syntax does what no other feature of C# has ever done - &lt;strong&gt;it breaks existing syntax&lt;/strong&gt;. Should I define in C# 3.0 a type named &lt;code&gt;dynamic&lt;/code&gt;, the following piece of code will take a whole different meaning in C# 4.0:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span&gt;dynamic&lt;/span&gt; GetCustomer()
{
    &lt;span&gt;dynamic&lt;/span&gt; customer = GetCustomerCOMObject();
    &lt;span style="color:blue;"&gt;return&lt;/span&gt; customer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;h5&gt;How it can be fixed&lt;/h5&gt;
&lt;p&gt;Using the &lt;code&gt;dynamic&lt;/code&gt; keyword is actually a built-in form of &lt;a href="http://weblogs.asp.net/okloeten/archive/2006/10/31/767349.aspx" target="_blank"&gt;Duck Typing&lt;/a&gt;. The idea is good and should be introduced into the language, but I&amp;#39;d like to suggest a different way of doing it:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;public&lt;/span&gt; &lt;span&gt;ICustomer&lt;/span&gt; GetCustomer()
{
    &lt;span style="color:blue;"&gt;dynamic&lt;/span&gt; &lt;span&gt;ICustomer&lt;/span&gt; customer = GetCustomerCOMObject();
    &lt;span style="color:blue;"&gt;return&lt;/span&gt; customer;
}&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here, what I get back is a dynamic dispatch object that must adhere to a specific interface. This means that &lt;strong&gt;the object graph is checked for conformity&lt;/strong&gt; against &lt;code&gt;ICustomer&lt;/code&gt; &lt;strong&gt;the moment it is cast in the dynamic scope &lt;/strong&gt;(i.e. returned from &lt;code&gt;GetCustomerCOMObject&lt;/code&gt;) and is from this moment on a typed object with dynamic dispatch under the hood. From this moment on, we couldn&amp;#39;t care less about whether this object uses dynamic dispatch or not, since we now treat it as a &lt;a href="http://en.wikipedia.org/wiki/Plain_Old_CLR_Object" target="_blank"&gt;POCO&lt;/a&gt;.&lt;br /&gt;This, along with removing of the ability to send dynamic dispatch objects through the call-stack (as parameters and return types), bringing them to the level of anonymous types, will help stop the deterioration of C# into a dynamic language.&lt;/p&gt;
&lt;h4&gt;Named and Optional Arguments&lt;/h4&gt;
&lt;p&gt;&lt;a title="Untitled by Long Zheng, CC-BY-NC-SA" href="http://flickr.com/photos/longzheng/2981755329/"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:5px 5px 5px 10px;border-right-width:0px;" height="181" alt="Untitled by Long Zheng, CC-BY-NC-SA" src="http://weblogs.asp.net/blogs/okloeten/WindowsLiveWriter/MyViewofC4.0_6C/2_3.jpg" width="260" align="right" border="0" /&gt;&lt;/a&gt;This is just silly. Really, this looks like some people cried &amp;quot;we don&amp;#39;t like overloads&amp;quot; hard enough and got some VB into the C# the rest of us liked the way it was. If you want to initialize your method with some of the parameters, use a builder pattern with an object initializer instead.&lt;/p&gt;
&lt;p&gt;Here, I&amp;#39;ll take the sample at the bottom of page 6 and fix it, C# 3.0 style:&lt;/p&gt;&lt;pre&gt;&lt;code&gt;&lt;span style="color:blue;"&gt;public void&lt;/span&gt; M(&lt;span style="color:blue;"&gt;int&lt;/span&gt; x, &lt;span&gt;MBuilder&lt;/span&gt; builder);

&lt;span style="color:blue;"&gt;public void&lt;/span&gt; M(&lt;span style="color:blue;"&gt;int&lt;/span&gt; x)
{
    &lt;span style="color:blue;"&gt;this&lt;/span&gt;.M(x, &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;MBuilder&lt;/span&gt;());
}

&lt;span style="color:blue;"&gt;public class&lt;/span&gt; &lt;span&gt;MBuilder&lt;/span&gt;
{
    &lt;span style="color:blue;"&gt;public&lt;/span&gt; MBuilder() { &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Y = 5; &lt;span style="color:blue;"&gt;this&lt;/span&gt;.Z = 7; }
    &lt;span style="color:blue;"&gt;public int&lt;/span&gt; Y { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
    &lt;span style="color:blue;"&gt;public int&lt;/span&gt; Z { &lt;span style="color:blue;"&gt;get&lt;/span&gt;; &lt;span style="color:blue;"&gt;set&lt;/span&gt;; }
}

M(1, &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;MBuilder&lt;/span&gt; { Y = 2, Z = 3 }); &lt;span&gt;// ordinary call of M&lt;/span&gt;
M(1, &lt;span style="color:blue;"&gt;new&lt;/span&gt; &lt;span&gt;MBuilder&lt;/span&gt; { Y = 2 });        &lt;span&gt;// omitting z – equivalent to M(1, 2, 7)&lt;/span&gt;
M(1);                                &lt;span&gt;// omitting both y and z – equivalent to M(1, 5, 7)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yes, I do realize it&amp;#39;s mainly for COM interop, but most people will just get either confused by all the syntax, abuse it or simply forget it ever existed.&lt;/p&gt;
&lt;h5&gt;What is wrong with it&lt;/h5&gt;
&lt;p&gt;It exists.&lt;/p&gt;
&lt;h5&gt;How it can be fixed&lt;/h5&gt;
&lt;p&gt;Remove it from C#. There - fixed.&lt;br /&gt;If you want optional parameters in your COM interop calls, just implement the correct overloads in the interface you create for use with the &lt;code&gt;dynamic&lt;/code&gt; keyword (see my suggestion for dynamic lookups) and the binding will be done at run time by the parameter names.&lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h4&gt;Variance, Covariance and Contravariance&lt;/h4&gt;
&lt;p&gt;These three features are long overdue and &lt;a href="http://weblogs.asp.net/okloeten/archive/2006/10/10/Generic-Type-Variance-in-C_2300_-and-the-CLR.aspx" target="_blank"&gt;finally&lt;/a&gt; make an appearance in the language. It&amp;#39;s a great feature and I would love to integrate it into my code as soon as I possibly can.&lt;br /&gt;I would love to know if there are plans to not only include reference conversions, but also the implicit and explicit conversion operators as qualifiers for VC&amp;amp;C.&lt;/p&gt;
&lt;h5&gt;What is wrong with it&lt;/h5&gt;
&lt;p&gt;&lt;a title="Anders Heilberg at book signing by DBegley, CC-BY" href="http://flickr.com/photos/begley/2979906130/"&gt;&lt;img style="border-top-width:0px;border-left-width:0px;border-bottom-width:0px;margin:5px 5px 5px 10px;border-right-width:0px;" height="180" alt="Anders Heilberg at book signing by DBegley, CC-BY" src="http://weblogs.asp.net/blogs/okloeten/WindowsLiveWriter/MyViewofC4.0_6C/3_3.jpg" width="260" align="right" border="0" /&gt;&lt;/a&gt;Although Variance is implicit, the others are explicit. Using the &lt;code&gt;Type&amp;lt;in T&amp;gt;&lt;/code&gt; / &lt;code&gt;Type&amp;lt;out T&amp;gt;&lt;/code&gt; notation is good for being explicit (for instance when you expect your interface to be expanded in the future), but it doesn&amp;#39;t have to be and can become a bit annoying over time.&lt;/p&gt;
&lt;h5&gt;How it can be fixed&lt;/h5&gt;
&lt;p&gt;The compiler can very easily infer the fact that your interface is either input-only or output-only and mark it as such for you. Language-wise, the explicit version should be kept available, for when you want to prevent someone (or yourself) from mistakenly adding a new method that breaks the your input / output only design.&lt;/p&gt;
&lt;h4&gt;&lt;/h4&gt;
&lt;h4&gt;Summary&lt;/h4&gt;
&lt;p&gt;It looks to me like the team behind C# is going in the wrong direction (DLR) instead of the right direction (&lt;a href="http://weblogs.asp.net/okloeten/archive/2006/10/24/720461.aspx" target="_blank"&gt;Spec#&lt;/a&gt;), slowly turning C# into a dynamic language. It looks like all of this is done for the sake of easy interop with dynamic languages and COM objects. It looks as though the designers have &lt;a href="http://en.wikipedia.org/wiki/Dynamic_Language_Runtime" target="_blank"&gt;succumbed&lt;/a&gt; to &lt;a href="http://www.ironruby.net/" target="_blank"&gt;peer&lt;/a&gt; &lt;a href="http://www.codeplex.com/IronPython/" target="_blank"&gt;pressure&lt;/a&gt;. There are so many features missing from C# and the above are nowhere near the top of my list.&lt;/p&gt;
&lt;p&gt;I can only hope someone is listening.&lt;/p&gt;
[Cross-Posted from &lt;a href="http://weblogs.asp.net/OKloeten/" target="_blank"&gt;&lt;i&gt;Omer van Kloeten&amp;#39;s .NET Zen&lt;/i&gt;&lt;/a&gt;, my English language weblog]&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=159464" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="C#" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/C_2300_/default.aspx" /></entry><entry><title>ארוחת הבלוגרים השישית - 05/11/2008</title><link rel="alternate" type="text/html" href="http://blogs.microsoft.co.il/blogs/omer/archive/2008/10/14/153449.aspx" /><id>http://blogs.microsoft.co.il/blogs/omer/archive/2008/10/14/153449.aspx</id><published>2008-10-14T15:14:01Z</published><updated>2008-10-14T15:14:01Z</updated><content type="html">&lt;p dir="rtl" align="right"&gt;&lt;a title="&amp;quot;Skirt Steak...just right&amp;quot; by Mike, CC-NC-SA" href="http://flickr.com/photos/anotherpintplease/1572027789/" target="_blank"&gt;&lt;img style="margin:0px 0px 5px 10px;" alt="&amp;quot;Skirt Steak...just right&amp;quot; by Mike, CC-NC-SA" src="http://farm3.static.flickr.com/2260/1572027789_4b2108f31e_m.jpg" align="right" border="0" /&gt;&lt;/a&gt; רואים את הסטייק מימין? רואים כמה שהוא עסיסי ועשוי בדיוק בצורה הנכונה? נכון שאתם רוצים כזה?&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;אז נגבו את הריר מהמקלדת ואשרו הגעתכם לארוחת הבלוגרים השישית שתתקיים ב&lt;strong&gt;חמישי לנובמבר בשעה 18:30&lt;/strong&gt;.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;אני מחכה לדעת בערך כמה אנשים מגיעים וכמה מהם אוכלי כשר לפני שאוכל להחליט על מקום, אז בבקשה רשמו בתגובות שאתם מגיעים*. אתם יכולים גם להרשם ל&lt;a href="http://www.facebook.com/event.php?eid=30664933919" target="_blank"&gt;אירוע בפייסבוק&lt;/a&gt;.&lt;/p&gt; &lt;p dir="rtl" align="right"&gt;ושיהיה בתיאבון! :)&lt;/p&gt; &lt;p dir="rtl" style="font-size:smaller;" align="right"&gt;* בפעם שעברה היו 22 איש, אז אני מניח שמובן למה אני צריך לדעת מראש כמה אנשים מגיעים.&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=153449" width="1" height="1"&gt;</content><author><name>omer</name><uri>http://blogs.microsoft.co.il/members/omer.aspx</uri></author><category term="קהילה" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_E705D405D905DC05D405_/default.aspx" /><category term="ארוחת בלוגרים" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D005E805D505D705EA05_+_D105DC05D505D205E805D905DD05_/default.aspx" /><category term="חומר מקורי" scheme="http://blogs.microsoft.co.il/blogs/omer/archive/tags/_D705D505DE05E805_+_DE05E705D505E805D905_/default.aspx" /></entry></feed>
