<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" 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/"><channel><title>Search results for 'app:weblogs' matching tag '.NET 4.0'</title><link>http://msmvps.com/search/SearchResults.aspx?q=app:weblogs&amp;tag=.NET+4.0&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tag '.NET 4.0'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>New Features in Visual Studio 2010</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/09/07/new-features-in-visual-studio-2010.aspx</link><pubDate>Mon, 07 Sep 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1721443</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;Visual Studio 2010 is approaching rapidly from the launch and with it a new set of features will also appear.&lt;/p&gt;  &lt;p&gt;One that I think is very important is the Architectural Tools that come with this new version, and elements like:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Dependency Graph      &lt;ul&gt;       &lt;li&gt;Filters using Direct Graph Markup Language (DGML) on top of the generated graph. &lt;/li&gt;        &lt;li&gt;Views as:          &lt;ul&gt;           &lt;li&gt;Dependency Matrix &lt;/li&gt;            &lt;li&gt;Forced Direct Layout &lt;/li&gt;            &lt;li&gt;Top to Bottom Layout &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Sequence Diagrams      &lt;ul&gt;       &lt;li&gt;Available on the Code Editor &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Unified Modeling Language (UML)      &lt;ul&gt;       &lt;li&gt;Usage of UML to define the project &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Use Cases (UC)      &lt;ul&gt;       &lt;li&gt;Creation of Use Cases &lt;/li&gt;        &lt;li&gt;Integration with TFS, since we can select an element in the use case and build, link or View the associated Work Items. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Layer Designer and Layer Validation      &lt;ul&gt;       &lt;li&gt;Possibility do build the Architecture of the solution and associate some validation elements that will always be enforced during the development process. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&amp;#160; To know more about this &lt;a href="http://blogs.msdn.com/somasegar/archive/2009/08/29/architecture-tools-in-vsts-2010.aspx" target="_blank"&gt;subject read this S.Somasegar post&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Another very important features are the Debugging and Profiling.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Debugging      &lt;ul&gt;       &lt;li&gt;Built in Debugger for MPI programs. Now with the new VS2010 we can select a cluster head node, how many cores you want, and hit F5 to debug your MPI program. &lt;/li&gt;        &lt;li&gt;SOA Debugging          &lt;ul&gt;           &lt;li&gt;Up until now, debugging Cluster SOA was limited to basic WCF/.Net style debugging with no cluster integration. &lt;/li&gt;            &lt;li&gt;In Visual Studio 2010, an add-in for Cluster SOA enables the SOA Settings tab, allowing you to choose a head node, debug nodes and services, deploy runtime libraries and clean up automatically. &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Profiling      &lt;ul&gt;       &lt;li&gt;VS Profiler can offer insight into performance issues &lt;/li&gt;        &lt;li&gt;Shows a comparison report across multiple runs or builds so you can easily see the effect of your changes. &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160; To know more about this &lt;a href="http://blogs.msdn.com/somasegar/archive/2009/08/07/debugging-profiling-and-analyzing-parallel-applications.aspx" target="_blank"&gt;subject read this S. Somasegar post&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Improvements in Entity Framework 4.0</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/08/06/improvements-in-entity-framework-4-0.aspx</link><pubDate>Thu, 06 Aug 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1713873</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;&amp;#160;&amp;#160; With .NET 4.0 a lot of new features and technologies will see the light, as long as others will get improved, and Entity Framework will be one of those technologies that will get improved.&lt;/p&gt;  &lt;p&gt;&amp;#160;&amp;#160; A lot of this changes are being made on the Query pipeline, that means that are being done on the translation from Linq to SQL code, and some of the changes in Beta 1 are the following:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Avoid projecting all columns in nested queries&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Instead of making a query for the complete set of columns and the make the projection on top of it, just make the projection and get only the needed columns&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Avoiding Unnecessary IS NULL Checks in LINQ to Entities Queries&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;remove the Is null check when using Joins&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Additional join elimination:&amp;#160; Eliminate parent table in “Child Left Outer Join Parent”&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Avoid having a child left outer join if no column from that relation is needed for the projection&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Using IN instead of nested OR’s&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Instead of having several Or’s in place such as “CategoryId = 1 OR CategoryID = 2 (…)” have “CategoryId In (1,2,…)”&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Translating more of LINQ’s GroupBy operator into GROUP BY&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Better use of the SQL Group By in order to simplify the query&lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Avoiding “Cast (1 as bit)”, using “1” instead&lt;/li&gt;    &lt;li&gt;Simplifying some queries that go against a subtype in a type hierarchy&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&amp;#160; Some of the changes after Beta 1:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Elimination of null sentinels &lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;In the output query there is often the constant 1 projected both in nested and in top-most queries. By avoiding it and reusing other columns for the same purpose in many cases we are able to avoid levels of nesting. &lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Additional Join Elimination &lt;/li&gt;    &lt;li&gt;Use of Inner Joins instead of Left Outer Joins when possible &lt;/li&gt;    &lt;li&gt;Provide mechanism for efficient queries on non-Unicode columns &lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;We now generate non-unicode constants and parameters when these are used in LINQ to Entities queries in comparisons with non-unicode columns. This allows indexes to be used by SQL Server. &lt;/li&gt;   &lt;/ul&gt;    &lt;li&gt;Improve the translation of the functions String.StartsWith, String.Contains and String.EndsWith in LINQ to Entites to use LIKE. &lt;/li&gt;    &lt;li&gt;Improve the translation of the canonical functions StartsWith, Contains and EndsWith to use LIKE (these canonical functions became available in .NET 4.0 Beta1) &lt;/li&gt;    &lt;li&gt;Collapse multiple Case statements into one &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&amp;#160;&amp;#160; You can read more about this topic on &lt;a href="http://blogs.msdn.com/adonet/archive/2009/08/05/improvements-to-the-generated-sql-in-net-4-0-beta1.aspx" target="_blank"&gt;this ADO.NET Team post&lt;/a&gt;.&lt;/p&gt;</description></item><item><title>Data Services – Can be ADO.NET or SQL – What’s the difference</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/07/07/data-services-can-be-ado-net-or-sql-what-s-the-difference.aspx</link><pubDate>Tue, 07 Jul 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1698623</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;Just a while ago I was talking about Data Services and suddenly a confusion between ADO.NET Data Services and SQL Data Services took place, because we were talking about different Data Services, and so in order to try to clarify the differences I remembered to write this post. &lt;/p&gt;  &lt;p&gt;There are two types of Data Services that are:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;SQL Data Services&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;em&gt;Cloud&lt;/em&gt; – at this moment is being converted from ACE (Activity, Container and Entity)&amp;#160; to TDS (Tabular Data Stream) as I’ve &lt;a href="http://msmvps.com/blogs/nunogodinho/archive/2009/07/06/experiments-with-the-new-sql-data-services.aspx"&gt;presented in this post&lt;/a&gt;. &lt;/li&gt;      &lt;li&gt;In this case we are talking about a Database in the &lt;em&gt;Cloud&lt;/em&gt; and the ultimate desire will be to just change the ConnectionString used.&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;ADO.NET Data Services aka. “Project Astoria”&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;This one is about making available a set of &lt;a href="http://msdn.microsoft.com/en-us/data/bb931106.aspx"&gt;REST Services on top of ADO.NET&lt;/a&gt;&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Highly Extensible:&lt;/li&gt;        &lt;ul&gt;         &lt;li&gt;Query Filtering (GET requests)&lt;/li&gt;          &lt;li&gt;Operation Filtering (PUT, POST, DELETE, etc requests)&lt;/li&gt;          &lt;li&gt;Making other Operations available with the same capabilities as the ones associated with ADO.NET Data Services.&lt;/li&gt;          &lt;ul&gt;           &lt;li&gt;Filter&lt;/li&gt;            &lt;li&gt;Sort&lt;/li&gt;            &lt;li&gt;Group&lt;/li&gt;            &lt;li&gt;Take&lt;/li&gt;            &lt;li&gt;Skip&lt;/li&gt;            &lt;li&gt;and so on.&lt;/li&gt;         &lt;/ul&gt;       &lt;/ul&gt;        &lt;li&gt;This layer can be placed on top of:&lt;/li&gt;        &lt;ul&gt;         &lt;li&gt;Entity Framework&lt;/li&gt;          &lt;li&gt;Linq-to-SQL&lt;/li&gt;          &lt;li&gt;Custom CLR Objects&lt;/li&gt;       &lt;/ul&gt;     &lt;/ul&gt;      &lt;li&gt;Where to know more:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;Overview: &lt;a href="http://msdn.microsoft.com/en-us/library/cc956153.aspx"&gt;http://msdn.microsoft.com/en-us/library/cc956153.aspx&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;Sample: &lt;a href="http://msdn.microsoft.com/en-us/magazine/cc748663.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc748663.aspx&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;      &lt;li&gt;Offline Version:&lt;/li&gt;      &lt;ul&gt;       &lt;li&gt;&lt;a href="http://channel9.msdn.com/pdc2008/TL08/"&gt;http://channel9.msdn.com/pdc2008/TL08/&lt;/a&gt;&lt;/li&gt;        &lt;li&gt;&lt;a href="http://blogs.msdn.com/astoriateam/archive/2008/10/22/astoria-futures-offline-enabled-data-services.aspx"&gt;http://blogs.msdn.com/astoriateam/archive/2008/10/22/astoria-futures-offline-enabled-data-services.aspx&lt;/a&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;Hope it helps you get the confusions out of discussions on this topic.&lt;/p&gt;</description></item><item><title>Interesting reading about Entity Framework 4.0</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/07/06/interesting-reading-about-entity-framework-4-0.aspx</link><pubDate>Mon, 06 Jul 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1698491</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;Entity Framework has suffered great changes and in order to know more about them I recommend the following reading:&lt;/p&gt;  &lt;p&gt;POCO (&lt;strong&gt;P&lt;/strong&gt;lain &lt;strong&gt;O&lt;/strong&gt;ld &lt;strong&gt;C&lt;/strong&gt;LR &lt;strong&gt;O&lt;/strong&gt;bject or Persistence ) in the Entity Framework 4.0&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/11/sneak-preview-persistence-ignorance-and-poco-in-entity-framework-4-0.aspx" target="_blank"&gt;Sneak Preview: Persistence Ignorance and POCO in Entity Framework 4.0&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;POCO in the Entity Framework: &lt;/li&gt; &lt;/ul&gt;  &lt;blockquote&gt;   &lt;p&gt;“Why is POCO important in Entity Framework? Is important because now we have the ability to really separate the Storage Model from the Conceptual Model, and being the Conceptual Model our &lt;strong&gt;normal&lt;/strong&gt; CLR Objects, that was not possible in previous versions of Entity Framework. This is a huge breakthrough for this 4.0 version. Is not perfect, and in this technologies it never is but it’s very interesting”&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;ol&gt;     &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/21/poco-in-the-entity-framework-part-1-the-experience.aspx" target="_blank"&gt;Part 1 - The Experience&lt;/a&gt; (Explains how to make this two parts of the POCO experience with Entity Framework 4.0, from making the Model to the designing of the POCO entities, as well as answering some interesting questions)&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/05/28/poco-in-the-entity-framework-part-2-complex-types-deferred-loading-and-explicit-loading.aspx" target="_blank"&gt;Part 2 – Complex Types, Deferred Loading and Explicit Loading&lt;/a&gt; (Goes further in the POCO entities and make changes shows how to implement Complex Types as well as configuring the Loading by using Deferred/Lazy Loading or Explicit Loading)&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/10/poco-in-the-entity-framework-part-3-change-tracking-with-poco.aspx" target="_blank"&gt;Part 3 – Change Tracking with POCO&lt;/a&gt; (Explains furthermore how the Change Tracking, that is so important in Entity Framework, works in POCO entities and how can it be configured by using Metadata) &lt;/li&gt;   &lt;/ol&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx" target="_blank"&gt;Using Repository and Unit of Work patterns with Entity Framework 4.0&lt;/a&gt; (Explains how to implement common patterns like &lt;a href="http://martinfowler.com/eaaCatalog/repository.html" target="_blank"&gt;Repository&lt;/a&gt; and &lt;a href="http://www.martinfowler.com/eaaCatalog/unitOfWork.html" target="_blank"&gt;Unit of Work&lt;/a&gt; using Entity Framework 4.0) &lt;/li&gt;    &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/archive/2009/06/22/announcing-entity-framework-feature-ctp-1.aspx" target="_blank"&gt;Entity Framework Feature CTP 1&lt;/a&gt; (Announcement of the Entity Framework CTP Features for .NET 4.0 Beta 1)&lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-self-tracking-entities-for-the-entity-framework.aspx" target="_blank"&gt;Feature CTP Walkthrough: Self Tracking Entities for Entity Framework&lt;/a&gt; (Explains the scenarios on where to use the Self Tracking Entities)&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-poco-templates-for-the-entity-framework.aspx" target="_blank"&gt;Feature CTP Walkthrough: POCO Templates for Entity Framework&lt;/a&gt; (Explains how to use POCO Templates, that is a kind of T4 Template in order to generate POCO entities)&lt;/li&gt;      &lt;li&gt;&lt;a href="http://blogs.msdn.com/adonet/pages/feature-ctp-walkthrough-code-only-for-the-entity-framework.aspx" target="_blank"&gt;Feature CTP Walkthrough: Code Only for Entity Framework&lt;/a&gt; (Explains how to Entity Framework without any model like EDMX, just code)&lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;p&gt;I hope you enjoy the reading.&lt;/p&gt;</description></item><item><title>Microsoft Releases Roadmap</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/06/03/microsoft-releases-roadmap.aspx</link><pubDate>Wed, 03 Jun 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1693750</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;A lot is being announced this days regarding Microsoft Products and Technologies, and so this is a little summary of all those information&amp;#39;s.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.neowin.net/news/main/09/05/29/microsoft-confirms-silverlight-3-to-launch-on-july-10" target="_blank"&gt;Silverlight 3.0 – July 10th 2009&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.azurejournal.com/2009/04/why-microsoft-wont-release-windows-azure-this-year-but-they-should/" target="_blank"&gt;Azure Business Model – In the next few weeks/months&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/presspass/features/2009/Jun09/06-02SteveGuggenheimer.mspx" target="_blank"&gt;Windows 7 – October 22nd 2009&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.sedodream.com/PermaLink,guid,01de7e0f-8fbc-4ea3-ac0b-45830ce12da1.aspx" target="_blank"&gt;Visual Studio 2010 and .NET Framework 4.0 – Last Quarter of 2009&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.computerworld.com/action/article.do?command=viewArticleBasic&amp;amp;articleId=9128520" target="_blank"&gt;Azure RTM – Last Quarter of 2009&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/presspass/features/2009/Apr09/04-15Office2010.mspx?rss_fdn=Top%20Stories" target="_blank"&gt;Office 2010 – First Half 2010&lt;/a&gt;       &lt;ul&gt;       &lt;li&gt;&lt;a href="http://www.findmysoft.com/news/Microsoft-Announces-Office-2010-codename-Office-14-Release-Date/" target="_blank"&gt;Exchange Server 2010 – Second Half 2009&lt;/a&gt; &lt;/li&gt;        &lt;li&gt;&lt;a href="http://www.findmysoft.com/news/Microsoft-Announces-Office-2010-codename-Office-14-Release-Date/" target="_blank"&gt;Office 2010 System – First Half 2010&lt;/a&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;</description></item><item><title>Exploiting covariance with LINQ to XML</title><link>http://msmvps.com/blogs/martin_honnen/archive/2009/06/01/exploiting-covariance-with-linq-to-xml.aspx</link><pubDate>Mon, 01 Jun 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1693522</guid><dc:creator>MartinH</dc:creator><description>&lt;p&gt;In my &lt;a href="http://msmvps.com/blogs/martin_honnen/archive/2009/05/31/exploiting-contravariance-with-linq-to-xml.aspx"&gt;last post&lt;/a&gt; I showed how the &lt;a href="http://msdn.microsoft.com/en-us/library/dd465120(VS.100).aspx"&gt;new contravariance feature in .NET 4.0/Visual Studio 2010 for type parameters of generic interfaces&lt;/a&gt; makes coding with LINQ to XML easier and more straightforward. In this post I will show how the &lt;a href="http://msdn.microsoft.com/en-us/library/9eekhta0(VS.100).aspx"&gt;covariance of the type parameter T of IEnumerable&amp;lt;T&amp;gt;&lt;/a&gt; also allows us to write LINQ to XML queries in a more straightforward way.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s assume we have the following XML document:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#a31515;"&gt;xml&lt;/span&gt; &lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;1.0&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;encoding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;utf-8&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color:green;"&gt; comment 1 --&amp;gt;&lt;br /&gt;  &amp;lt;foo&amp;gt;foo 1&amp;lt;/foo&amp;gt;&lt;br /&gt;  &amp;lt;bar&amp;gt;bar 1&amp;lt;/bar&amp;gt;&lt;br /&gt;  &amp;lt;!-- comment 2 --&amp;gt;&lt;br /&gt;  &amp;lt;foo&amp;gt;foo 2&amp;lt;/foo&amp;gt;&lt;br /&gt;  &amp;lt;bar&amp;gt;2&amp;lt;/bar&amp;gt;&lt;br /&gt;  &amp;lt;!-- comment 3 &lt;/span&gt;&lt;span style="color:blue;"&gt;--&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;and we want to transform that document into a second one with the same root element having the same child nodes, except where all &amp;#39;bar&amp;#39; child elements of the &amp;#39;root&amp;#39; element node have been removed. So the result should look as follows:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#a31515;"&gt;xml&lt;/span&gt; &lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;1.0&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;encoding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;utf-8&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;!--&lt;/span&gt;&lt;span style="color:green;"&gt; comment 1 --&amp;gt;&lt;br /&gt;  &amp;lt;foo&amp;gt;foo 1&amp;lt;/foo&amp;gt;&lt;br /&gt;  &amp;lt;!-- comment 2 --&amp;gt;&lt;br /&gt;  &amp;lt;foo&amp;gt;foo 2&amp;lt;/foo&amp;gt;&lt;br /&gt;  &amp;lt;!-- comment 3 &lt;/span&gt;&lt;span style="color:blue;"&gt;--&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;A first attempt to achieve that with LINQ to XML could look as follows:&lt;/p&gt;
&lt;pre&gt;            XDocument doc1 = XDocument.Load(&lt;span style="color:#a31515;"&gt;@&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            XDocument doc2 =&lt;br /&gt;                &lt;span style="color:blue;"&gt;new&lt;/span&gt; XDocument(&lt;br /&gt;                    &lt;span style="color:blue;"&gt;new&lt;/span&gt; XElement(doc1.Root.Name,&lt;br /&gt;                        doc1&lt;br /&gt;                        .Root&lt;br /&gt;                        .Nodes()&lt;br /&gt;                        .Except(&lt;br /&gt;                            doc1&lt;br /&gt;                            .Root&lt;br /&gt;                            .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;))));&lt;br /&gt;&lt;br /&gt;            doc2.Save(Console.Out);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;So we create a new XDocument with a new root XElement having the same name as the Root of the first XDocument where all child nodes except of the &amp;#39;bar&amp;#39; child elements are copied. &lt;/p&gt;
&lt;p&gt;Looks nice and straightforward only if you try to compile that with Visual Studio 2008/.NET 3.5 you get the following error: &amp;quot;Argument &amp;#39;2&amp;#39;: cannot convert from &amp;#39;System.Collections.Generic.IEnumerable&amp;lt;System.Xml.Linq.XElement&amp;gt;&amp;#39; to &amp;#39;System.Collections.Generic.IEnumerable&amp;lt;System.Xml.Linq.XNode&amp;gt;&amp;#39;&amp;quot;. &lt;/p&gt;
&lt;p&gt;The problem is that the Nodes() call returns an IEnumerable&amp;lt;XNode&amp;gt; and then the following Except() call also needs an IEnumerable&amp;lt;XNode&amp;gt; as its argument while Elements(&amp;quot;bar&amp;quot;) gives us an IEnumerable&amp;lt;XElement&amp;gt;. With generic interfaces being invariant in .NET 3.5 we can&amp;#39;t pass that IEnumerable&amp;lt;XElement&amp;gt; in for an IEnumerable&amp;lt;XNode&amp;gt;, although XElement is a class derived from XNode.&lt;/p&gt;
&lt;p&gt;As a workaround we can first cast the IEnumerable&amp;lt;XElement&amp;gt; to an IEnumerable&amp;lt;XNode&amp;gt;:&lt;/p&gt;
&lt;pre&gt;            XDocument doc1 = XDocument.Load(&lt;span style="color:#a31515;"&gt;@&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            XDocument doc2 =&lt;br /&gt;                &lt;span style="color:blue;"&gt;new&lt;/span&gt; XDocument(&lt;br /&gt;                    &lt;span style="color:blue;"&gt;new&lt;/span&gt; XElement(doc1.Root.Name,&lt;br /&gt;                        doc1&lt;br /&gt;                        .Root&lt;br /&gt;                        .Nodes()&lt;br /&gt;                        .Except(&lt;br /&gt;                            doc1&lt;br /&gt;                            .Root&lt;br /&gt;                            .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;)&lt;br /&gt;                            .Cast&amp;lt;XNode&amp;gt;())));&lt;br /&gt;&lt;br /&gt;            doc2.Save(Console.Out);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;That way it compiles fine and produces the wanted result with .NET 3.5, only it seems desirable that you would not need that Cast&amp;lt;XNode&amp;gt;() call.&lt;/p&gt;
&lt;p&gt;The good news is that starting with .NET 4.0 the type parameter T of IEnumerable&amp;lt;T&amp;gt; is covariant meaning where an IEnumerable&amp;lt;T&amp;gt; of a certain type T is expected we can always pass in an IEnumerable&amp;lt;T2&amp;gt; where T2 is type derived from T, as in our example where XElement is a subclass of XNode (or subsubclass to be precise).&lt;/p&gt;
&lt;p&gt;Thus with .NET 4.0 the following compiles and works fine:&lt;/p&gt;
&lt;pre&gt;            XDocument doc1 = XDocument.Load(&lt;span style="color:#a31515;"&gt;@&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            XDocument doc2 =&lt;br /&gt;                &lt;span style="color:blue;"&gt;new&lt;/span&gt; XDocument(&lt;br /&gt;                    &lt;span style="color:blue;"&gt;new&lt;/span&gt; XElement(doc1.Root.Name,&lt;br /&gt;                        doc1&lt;br /&gt;                        .Root&lt;br /&gt;                        .Nodes()&lt;br /&gt;                        .Except(&lt;br /&gt;                            doc1&lt;br /&gt;                            .Root&lt;br /&gt;                            .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;))));&lt;br /&gt;&lt;br /&gt;            doc2.Save(Console.Out);&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Exploiting contravariance with LINQ to XML</title><link>http://msmvps.com/blogs/martin_honnen/archive/2009/05/31/exploiting-contravariance-with-linq-to-xml.aspx</link><pubDate>Sun, 31 May 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1693493</guid><dc:creator>MartinH</dc:creator><description>&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd233054(VS.100).aspx"&gt;Covariance and contravariance for generic interfaces are new features in C# and VB.NET&lt;/a&gt; in Visual Studio 2010 respectively the .NET framework 4.0. Generic interfaces like IEnumerable&amp;lt;T&amp;gt; or IEqualityComparer&amp;lt;T&amp;gt; in the .NET framework 4.0 use these new features. Starting with .NET 4.0 the type parameter T in &lt;a href="http://msdn.microsoft.com/en-us/library/ms132151(VS.100).aspx"&gt;IEqualityComparer&amp;lt;T&amp;gt;&lt;/a&gt; is contravariant. That can make coding with LINQ to XML easier, as the class &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.xnodeequalitycomparer(VS.100).aspx"&gt;XNodeEqualityComparer&lt;/a&gt; implements IEqualityComparer&amp;lt;XNode&amp;gt; where XNode is a common base class for other LINQ to XML classes like XElement.&lt;/p&gt;
&lt;p&gt;Let&amp;#39;s look at an example. Assume we have the following XML document&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;?&lt;/span&gt;&lt;span style="color:#a31515;"&gt;xml&lt;/span&gt; &lt;span style="color:red;"&gt;version&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;1.0&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:red;"&gt;encoding&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;utf-8&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt; &lt;span style="color:blue;"&gt;?&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;items&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;a&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;b&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;2&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;a&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;1&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;c&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;3&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;c&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;foo&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;      &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;3&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;bar&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;item&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;items&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;root&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;and we want to use LINQ to XML to extract distinct items where we use XNodeEqualityComparer to compare the &amp;#39;item&amp;#39; elements in the XML document.&lt;/p&gt;
&lt;p&gt;You could be tempted to try it as follows:&lt;/p&gt;
&lt;pre&gt;            XDocument doc = XDocument.Load(&lt;span style="color:#a31515;"&gt;&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            var distinctItems =&lt;br /&gt;                doc&lt;br /&gt;                .Root&lt;br /&gt;                .Element(&lt;span style="color:#a31515;"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;item&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Distinct(&lt;span style="color:blue;"&gt;new&lt;/span&gt; XNodeEqualityComparer())&lt;br /&gt;                .Select(i =&amp;gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; { foo = (&lt;span style="color:blue;"&gt;string&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;), bar = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;) });&lt;br /&gt;&lt;br /&gt;            &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (var item &lt;span style="color:blue;"&gt;in&lt;/span&gt; distinctItems)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(item);&lt;br /&gt;            }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;but with .NET 3.5 that does not compile, complaining &amp;quot;Instance argument: cannot convert from &amp;#39;System.Collections.Generic.IEnumerable&amp;lt;System.Xml.Linq.XElement&amp;gt;&amp;#39; to &amp;#39;System.Collections.Generic.IEnumerable&amp;lt;System.Xml.Linq.XNode&amp;gt;&amp;#39;&amp;quot; on the Distinct(new XNodeEqualityComparer()) call. That happens because Elements(&amp;quot;item&amp;quot;) gives us an IEnumerable&amp;lt;XElement&amp;gt; and subsequently the Distinct method wants an IEqualityComparer&amp;lt;XElement&amp;gt; to be passed in while we only pass in an IEqualityComparer&amp;lt;XNode&amp;gt;. &lt;/p&gt;
&lt;p&gt;With .NET 3.5 to work around that problem we first have to cast IEnumerable&amp;lt;XElement&amp;gt; up to IEnumerable&amp;lt;XNode&amp;gt; before we call Distinct(new XNodeEqualityComparer()) and then down again after the Distinct() call:&lt;/p&gt;
&lt;pre&gt;            XDocument doc = XDocument.Load(&lt;span style="color:#a31515;"&gt;&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            var distinctItems =&lt;br /&gt;                doc&lt;br /&gt;                .Root&lt;br /&gt;                .Element(&lt;span style="color:#a31515;"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;item&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Cast&amp;lt;XNode&amp;gt;()&lt;br /&gt;                .Distinct(&lt;span style="color:blue;"&gt;new&lt;/span&gt; XNodeEqualityComparer())&lt;br /&gt;                .Cast&amp;lt;XElement&amp;gt;()&lt;br /&gt;                .Select(i =&amp;gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; { foo = (&lt;span style="color:blue;"&gt;string&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;), bar = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;) });&lt;br /&gt;&lt;br /&gt;            &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (var item &lt;span style="color:blue;"&gt;in&lt;/span&gt; distinctItems)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(item);&lt;br /&gt;            }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;That compiles fine and nicely returns only distinct items:&lt;/p&gt;
&lt;p&gt;{ foo = a, bar = 1 }&lt;br /&gt;{ foo = b, bar = 2 }&lt;br /&gt;{ foo = c, bar = 3 }&lt;/p&gt;
&lt;p&gt;With .NET 4.0 however the type parameter T of IEqualityComparer is contravariant meaning if we have a method expecting an IEqualityComparer&amp;lt;XElement&amp;gt; it suffices to use a base type of XElement like XNode and thus with .NET 4.0 our original attempt compiles and runs fine:&lt;/p&gt;
&lt;pre&gt;            XDocument doc = XDocument.Load(&lt;span style="color:#a31515;"&gt;&amp;quot;XMLFile1.xml&amp;quot;&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;            var distinctItems =&lt;br /&gt;                doc&lt;br /&gt;                .Root&lt;br /&gt;                .Element(&lt;span style="color:#a31515;"&gt;&amp;quot;items&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Elements(&lt;span style="color:#a31515;"&gt;&amp;quot;item&amp;quot;&lt;/span&gt;)&lt;br /&gt;                .Distinct(&lt;span style="color:blue;"&gt;new&lt;/span&gt; XNodeEqualityComparer())&lt;br /&gt;                .Select(i =&amp;gt; &lt;span style="color:blue;"&gt;new&lt;/span&gt; { foo = (&lt;span style="color:blue;"&gt;string&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;foo&amp;quot;&lt;/span&gt;), bar = (&lt;span style="color:blue;"&gt;int&lt;/span&gt;)i.Element(&lt;span style="color:#a31515;"&gt;&amp;quot;bar&amp;quot;&lt;/span&gt;) });&lt;br /&gt;&lt;br /&gt;            &lt;span style="color:blue;"&gt;foreach&lt;/span&gt; (var item &lt;span style="color:blue;"&gt;in&lt;/span&gt; distinctItems)&lt;br /&gt;            {&lt;br /&gt;                Console.WriteLine(item);&lt;br /&gt;            }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>[VSTS 2010] Disponible para Descarga el Beta 1 de VSTS y .Net Framework 4.0</title><link>http://msmvps.com/blogs/ffagas/archive/2009/05/22/vsts-2010-disponible-para-descarga-el-beta-1-de-vsts-y-net-framework-4-0.aspx</link><pubDate>Fri, 22 May 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692990</guid><dc:creator>ffagas</dc:creator><description>&lt;p align="justify"&gt;Ahora ya pueden descargar el Beta 1 de &lt;a href="https://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx"&gt;Visual Studio Team System&lt;/a&gt; el cual brinda un sin n&amp;uacute;mero de nuevas caracter&amp;iacute;sticas las cuales pueden revisar en el siguiente blog (&lt;a href="http://blogs.msdn.com/jasonz/archive/2009/05/18/announcing-vs2010-net-framework-4-0-beta-1.aspx" title="http://blogs.msdn.com/jasonz/archive/2009/05/18/announcing-vs2010-net-framework-4-0-beta-1.aspx"&gt;http://blogs.msdn.com/jasonz/archive/2009/05/18/announcing-vs2010-net-framework-4-0-beta-1.aspx&lt;/a&gt;), as&amp;iacute; como el .Net Framework 4.0 Beta 1.&amp;nbsp; A continuaci&amp;oacute;n la lista de herramientas disponibles para descargar con su respectivo enlace.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;.NET Framework&lt;/b&gt; &lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=147415"&gt;Microsoft .NET Framework 4.0 Beta 1&lt;/a&gt;&lt;/span&gt; &lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=147417"&gt;Microsoft .NET Framework 4.0 Client Profile Beta 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Documentaci&amp;oacute;n&lt;/b&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/dd831853(VS.100).aspx"&gt;&lt;span style="color:#669966;"&gt;Visual Studio 2010 Beta 1&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/w0x726c2(VS.100).aspx"&gt;&lt;span style="color:#669966;"&gt;.NET Framework 4 Beta 1&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Herramientas:&lt;/b&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;b&gt;Professional&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147408"&gt;Visual Studio 2010 Professional Beta 1 &amp;ndash; Web Installer&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=150591"&gt;Visual Studio 2010 Professional Beta 1 &amp;ndash; ISO&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;b&gt;Team System&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147407"&gt;Visual Studio Team System 2010 Team Suite Beta 1 &amp;ndash; Web Installer&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=150592"&gt;Visual Studio Team System 2010 Team Suite Beta 1 - ISO&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147420"&gt;Visual Studio Team System 2010 Test Load Agent Beta 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147412"&gt;Visual Studio Team System 2010 Team Foundation Server Beta 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147413"&gt;Microsoft Visual Studio Lab Management 2010 Beta 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147414"&gt;Visual Studio Team System 2010 Lab Agent Beta 1&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;b&gt;Herramientas adicionales&lt;/b&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147421"&gt;Microsoft Visual Studio 2010 Remote Debugger (Beta 1)&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147419"&gt;Visual Studio 2010 Shell (Integrated) Beta 1 Redistributable Package&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;span style="text-decoration:underline;"&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkId=147418"&gt;Visual Studio 2010 Shell (Isolated) Beta 1 Redistributable Package&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/blockquote&gt;</description></item><item><title>What is new in System.Xml in .NET 4.0/Visual Studio 2010</title><link>http://msmvps.com/blogs/martin_honnen/archive/2009/05/21/what-is-new-in-system-xml-in-net-4-0-visual-studio-2010.aspx</link><pubDate>Thu, 21 May 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1693044</guid><dc:creator>MartinH</dc:creator><description>&lt;p&gt;Beta 1 of the .NET framework 4.0 and of Visual Studio 2010 has been released a few days ago. Although the &lt;a href="http://msdn.microsoft.com/en-us/library/dd409230(VS.100).aspx"&gt;&amp;quot;What&amp;#39;s new&amp;quot; document&lt;/a&gt; does not list any new features in System.Xml or LINQ to XML I am browsing through the documentation to find new features or changes in APIs.&lt;/p&gt;
&lt;p&gt;So far I have found the following:&lt;/p&gt;
&lt;p&gt;With LINQ to XML the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.saveoptions(VS.100).aspx"&gt;SaveOptions enumeration&lt;/a&gt; has a new flag named OmitDuplicateNamespaces. That is particularly useful with VB.NET XML literals as using them you might end up with more namespace declaration attributes as you want resulting in superfluous namespace declarations on child or descendant elements when you save/serialize a LINQ to XML XDocument or XElement.&lt;/p&gt;
&lt;p&gt;Here is an example in VB.NET with .NET 3.5:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; System&lt;br /&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; System.Xml.Linq&lt;br /&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; &amp;lt;xmlns=&lt;span style="color:#a31515;"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Sub&lt;/span&gt; Main()&lt;br /&gt;        &lt;span style="color:blue;"&gt;Dim&lt;/span&gt; html &lt;span style="color:blue;"&gt;As&lt;/span&gt; XElement = _&lt;br /&gt;        &amp;lt;html&amp;gt;&lt;br /&gt;            &amp;lt;head&amp;gt;&lt;br /&gt;                &amp;lt;title&amp;gt;Example&amp;lt;/title&amp;gt;&lt;br /&gt;            &amp;lt;/head&amp;gt;&lt;br /&gt;            &amp;lt;body&amp;gt;&lt;br /&gt;            &amp;lt;/body&amp;gt;&lt;br /&gt;        &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;        html.&amp;lt;body&amp;gt;(0).Add(GetParagraphs())&lt;br /&gt;&lt;br /&gt;        html.Save(Console.Out)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Function&lt;/span&gt; GetParagraphs() &lt;span style="color:blue;"&gt;As&lt;/span&gt; IEnumerable(Of XElement)&lt;br /&gt;        &lt;span style="color:blue;"&gt;Dim&lt;/span&gt; ps() &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;String&lt;/span&gt; = {&lt;span style="color:#a31515;"&gt;&amp;quot;Paragraph 1.&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Paragraph 2.&amp;quot;&lt;/span&gt;}&lt;br /&gt;        &lt;span style="color:blue;"&gt;Return&lt;/span&gt; (From p &lt;span style="color:blue;"&gt;In&lt;/span&gt; ps &lt;span style="color:blue;"&gt;Select&lt;/span&gt; &amp;lt;p&amp;gt;&amp;lt;%= p %&amp;gt;&amp;lt;/p&amp;gt;)&lt;br /&gt;    &lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Its output is as follows:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;html&lt;/span&gt; &lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;head&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;title&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Example&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;title&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;head&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;body&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt; &lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Paragraph 1.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt; &lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Paragraph 2.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;body&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;html&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;As you can see, the namespace declarations on the &amp;#39;p&amp;#39; elements are redundant as the namespace is already defined on the &amp;#39;html&amp;#39; root element.&lt;/p&gt;
&lt;p&gt;With .NET 4.0 and the SaveOptions.OmitDuplicateNamespaces flag you can avoid them as follows:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; System&lt;br /&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; System.Xml.Linq&lt;br /&gt;&lt;span style="color:blue;"&gt;Imports&lt;/span&gt; &amp;lt;xmlns=&lt;span style="color:#a31515;"&gt;&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&lt;/span&gt;&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;Module&lt;/span&gt; Module1&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Sub&lt;/span&gt; Main()&lt;br /&gt;        &lt;span style="color:blue;"&gt;Dim&lt;/span&gt; html &lt;span style="color:blue;"&gt;As&lt;/span&gt; XElement = _&lt;br /&gt;        &amp;lt;html&amp;gt;&lt;br /&gt;            &amp;lt;head&amp;gt;&lt;br /&gt;                &amp;lt;title&amp;gt;Example&amp;lt;/title&amp;gt;&lt;br /&gt;            &amp;lt;/head&amp;gt;&lt;br /&gt;            &amp;lt;body&amp;gt;&lt;br /&gt;            &amp;lt;/body&amp;gt;&lt;br /&gt;        &amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;        html.&amp;lt;body&amp;gt;(0).Add(GetParagraphs())&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        html.Save(Console.Out, SaveOptions.OmitDuplicateNamespaces)&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Sub&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;Function&lt;/span&gt; GetParagraphs() &lt;span style="color:blue;"&gt;As&lt;/span&gt; IEnumerable(Of XElement)&lt;br /&gt;        &lt;span style="color:blue;"&gt;Dim&lt;/span&gt; ps() &lt;span style="color:blue;"&gt;As&lt;/span&gt; &lt;span style="color:blue;"&gt;String&lt;/span&gt; = {&lt;span style="color:#a31515;"&gt;&amp;quot;Paragraph 1.&amp;quot;&lt;/span&gt;, &lt;span style="color:#a31515;"&gt;&amp;quot;Paragraph 2.&amp;quot;&lt;/span&gt;}&lt;br /&gt;        &lt;span style="color:blue;"&gt;Return&lt;/span&gt; (From p &lt;span style="color:blue;"&gt;In&lt;/span&gt; ps &lt;span style="color:blue;"&gt;Select&lt;/span&gt; &amp;lt;p&amp;gt;&amp;lt;%= p %&amp;gt;&amp;lt;/p&amp;gt;)&lt;br /&gt;    &lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Function&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;End&lt;/span&gt; &lt;span style="color:blue;"&gt;Module&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;
Now the output is fine:&lt;/p&gt;
&lt;pre&gt;&lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;html&lt;/span&gt; &lt;span style="color:red;"&gt;xmlns&lt;/span&gt;&lt;span style="color:blue;"&gt;=&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;http://www.w3.org/1999/xhtml&lt;/span&gt;&lt;span style="color:black;"&gt;&amp;quot;&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;head&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;title&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Example&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;title&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;head&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;body&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Paragraph 1.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;    &lt;span style="color:blue;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;Paragraph 2.&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;p&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;  &lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;body&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="color:blue;"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color:#a31515;"&gt;html&lt;/span&gt;&lt;span style="color:blue;"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;Have you ever wondered why an XDocument or XElement in .NET 3.5 could be saved to a TextWriter or a file or an XmlWriter but not directly to a Stream? In .NET 3.5 you need to construct an XmlWriter or TextWriter over a Stream but now in .NET 4.0 you can save directly to a Stream: &lt;a href="http://msdn.microsoft.com/en-us/library/cc838476(VS.100).aspx"&gt;XDocument.Save(Stream)&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/cc838604(VS.100).aspx"&gt;XElement.Save(Stream)&lt;/a&gt;. No functionality gain but a convenient addition, for instance when you want to send the serialization of an XDocument or XElement to the request stream of an HttpWebRequest. There are also corresponding Load methods taking a Stream as the input, &lt;a href="http://msdn.microsoft.com/en-us/library/cc838349(VS.100).aspx"&gt;XDocument.Load(Stream)&lt;/a&gt;, &lt;a href="http://msdn.microsoft.com/en-us/library/cc838544(VS.100).aspx"&gt;XElement.Load(Stream)&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;There is also a new &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.readeroptions(VS.100).aspx"&gt;enumeration ReaderOptions&lt;/a&gt; in System.Xml.Linq but so far I have not found any method or property using that enumeration.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;XmlReaderSettings has a new property &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.dtdprocessing(VS.100).aspx"&gt;DtdProcessing&lt;/a&gt; that replaces the now obsolete &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreadersettings.prohibitdtd(VS.100).aspx"&gt;ProhibitDtd&lt;/a&gt; property. With the boolean property ProhibitDtd you could choose to either allow DTD parsing/processing or to prohibit it. With the new DtdProcessing property you have now three choices, prohibit, parse, or ignore. Ignore could give you performance benefits over parse. for instance the following parses the W3C home page twice, once ignoring the DTD, once parsing/processing it:&lt;/p&gt;
&lt;pre&gt;            Stopwatch watch = &lt;span style="color:blue;"&gt;new&lt;/span&gt; Stopwatch();&lt;br /&gt;            XmlReaderSettings settings = &lt;span style="color:blue;"&gt;new&lt;/span&gt; XmlReaderSettings();&lt;br /&gt;            settings.DtdProcessing = DtdProcessing.Ignore;&lt;br /&gt;            watch.Start();&lt;br /&gt;            &lt;span style="color:blue;"&gt;using&lt;/span&gt; (XmlReader reader = XmlReader.Create(&lt;span style="color:#a31515;"&gt;@&amp;quot;http://www.w3.org/&amp;quot;&lt;/span&gt;, settings))&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color:blue;"&gt;while&lt;/span&gt; (reader.Read())&lt;br /&gt;                {&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;DtdProcessing.Ignore: Elapsed time: {0}&amp;quot;&lt;/span&gt;, watch.Elapsed);&lt;br /&gt;&lt;br /&gt;            settings.DtdProcessing = DtdProcessing.Parse;&lt;br /&gt;            watch.Start();&lt;br /&gt;            &lt;span style="color:blue;"&gt;using&lt;/span&gt; (XmlReader reader = XmlReader.Create(&lt;span style="color:#a31515;"&gt;@&amp;quot;http://www.w3.org/&amp;quot;&lt;/span&gt;, settings))&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color:blue;"&gt;while&lt;/span&gt; (reader.Read())&lt;br /&gt;                {&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;            watch.Stop();&lt;br /&gt;            Console.WriteLine(&lt;span style="color:#a31515;"&gt;&amp;quot;DtdProcessing.Parse: Elapsed time: {0}&amp;quot;&lt;/span&gt;, watch.Elapsed);&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The output for me here is&lt;/p&gt;
&lt;p&gt;DtdProcessing.Ignore: Elapsed time: 00:00:01.5245222&lt;br /&gt;DtdProcessing.Parse: Elapsed time: 00:00:09.1677892&lt;/p&gt;
&lt;p&gt;so ignoring the DTD is about nine times faster for that sample document. On the other hand if the DTD defines any entities that are then referenced in the XML document ignoring the DTD would give you an exception:&lt;/p&gt;
&lt;pre&gt;            XmlReaderSettings settings = &lt;span style="color:blue;"&gt;new&lt;/span&gt; XmlReaderSettings();&lt;br /&gt;            settings.DtdProcessing = DtdProcessing.Ignore;&lt;br /&gt;&lt;br /&gt;            &lt;span style="color:blue;"&gt;string&lt;/span&gt; xhtml = &lt;span style="color:#a31515;"&gt;@&amp;quot;&amp;lt;!DOCTYPE html &lt;br /&gt;     PUBLIC &amp;quot;&amp;quot;-//W3C//DTD XHTML 1.0 Strict//EN&amp;quot;&amp;quot;&lt;br /&gt;     &amp;quot;&amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;html xml:lang=&amp;quot;&amp;quot;en&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;title&amp;gt;Example&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;lt;p&amp;gt;Price is: 100 &amp;amp;euro;&amp;lt;/p&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&amp;quot;&lt;/span&gt;;&lt;br /&gt;            &lt;span style="color:blue;"&gt;using&lt;/span&gt; (XmlReader reader = XmlReader.Create(&lt;span style="color:blue;"&gt;new&lt;/span&gt; StringReader(xhtml), settings))&lt;br /&gt;            {&lt;br /&gt;                &lt;span style="color:blue;"&gt;while&lt;/span&gt; (reader.Read()) { }&lt;br /&gt;            }&lt;br /&gt;&lt;/pre&gt;
&lt;p&gt;throws the exception &amp;quot;Reference to undeclared entity &amp;#39;euro&amp;#39;&amp;quot;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;That&amp;#39;s all I have found so far, I will edit this post when I find more.&lt;/p&gt;
&lt;p&gt;[edit 2009-05-26] I have now found a page &amp;quot;&lt;a href="http://msdn.microsoft.com/en-us/library/1k76xshy(VS.100).aspx"&gt;What&amp;#39;s new in System.Xml&lt;/a&gt;&amp;quot; in the .NET framework 4 Beta 1 documentation. Oddly enough it lists LINQ to XML and the XSLT compiler as new features although both were introduced in .NET 3.5. It also mentions new methods in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlconvert(VS.100).aspx"&gt;XmlConvert&lt;/a&gt; class.&lt;/p&gt;</description></item><item><title>Visual Studio 2010 and .NET Framework 4.0 Beta 1 Just Released</title><link>http://msmvps.com/blogs/nunogodinho/archive/2009/05/20/visual-studio-2010-and-net-framework-4-0-beta-1-just-released.aspx</link><pubDate>Wed, 20 May 2009 05:00:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1692783</guid><dc:creator>NunoGodinho</dc:creator><description>&lt;p&gt;The &lt;a href="http://blogs.msdn.com/somasegar/archive/2009/05/18/visual-studio-2010-and-net-fx-4-beta-1-ships.aspx" target="_blank"&gt;Beta 1 release of Visual Studio 2010, .NET Framework and Visual Studio Team Foundation Server Beta 1 was release on the last 18th of May&lt;/a&gt;, just last Monday, this for MSDN Subscribers and today for Non-MSDN Subscribers, and it will bring great enhancements in several levels. You can install it Side-By-Side with your existing Visual Studio Edition and try it, but don’t forget to read the ReadMe file for both &lt;a href="http://go.microsoft.com/fwlink/?LinkId=143397" target="_blank"&gt;Visual Studio 2010&lt;/a&gt; and &lt;a href="http://go.microsoft.com/fwlink/?LinkId=143398" target="_blank"&gt;.NET Framework 4.0&lt;/a&gt; in order to know what to expect. I still think that is better to test this version on a Virtual Machine, but you can choose what to do.&lt;/p&gt;  &lt;p&gt;A quick look at some of the Enhancements:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;.NET Framework 4.0&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;Main Technologies          &lt;ul&gt;           &lt;li&gt;WPF 4.0 &lt;/li&gt;            &lt;li&gt;WCF 4.0 &lt;/li&gt;            &lt;li&gt;WF 4.0 &lt;/li&gt;            &lt;li&gt;ASP.NET 4.0 &lt;/li&gt;            &lt;li&gt;ASP.NET AJAX 4.0 &lt;/li&gt;            &lt;li&gt;Entity Framework 2.0 &lt;/li&gt;            &lt;li&gt;Data Services 2.0 &lt;/li&gt;            &lt;li&gt;Project &amp;quot;Velocity&amp;quot; &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Managed Languages          &lt;ul&gt;           &lt;li&gt;VB              &lt;ul&gt;               &lt;li&gt;Implicit Line Continuation &lt;/li&gt;                &lt;li&gt;Multi-line Lambdas &lt;/li&gt;                &lt;li&gt;Statement Lambdas &lt;/li&gt;                &lt;li&gt;Auto Properties &lt;/li&gt;             &lt;/ul&gt;           &lt;/li&gt;            &lt;li&gt;C#              &lt;ul&gt;               &lt;li&gt;Named Parameters &lt;/li&gt;                &lt;li&gt;Optional Parameters &lt;/li&gt;             &lt;/ul&gt;           &lt;/li&gt;            &lt;li&gt;F# &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;        &lt;li&gt;Other Elements          &lt;ul&gt;           &lt;li&gt;Parallel Linq &lt;/li&gt;            &lt;li&gt;Managed Extensibility Framework &lt;/li&gt;            &lt;li&gt;DLR Built-In &lt;/li&gt;            &lt;li&gt;No need for PIAs – New way to Interoperate &lt;/li&gt;            &lt;li&gt;Generic Covarience &lt;/li&gt;            &lt;li&gt;Generic Contravariance &lt;/li&gt;            &lt;li&gt;CLR running In-Proc Side-by-Side &lt;/li&gt;            &lt;li&gt;Code Contracts &lt;/li&gt;            &lt;li&gt;Background GC &lt;/li&gt;         &lt;/ul&gt;       &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Visual Studio 2010&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;WPF-Based Editor &lt;/li&gt;        &lt;li&gt;New Look &amp;amp; Feel &lt;/li&gt;        &lt;li&gt;Improved WPF Tooling &lt;/li&gt;        &lt;li&gt;MVC Tooling &lt;/li&gt;        &lt;li&gt;Dynamic Data Tooling &lt;/li&gt;        &lt;li&gt;Sharepoint Tooling &lt;/li&gt;        &lt;li&gt;Click-Once Enhancements for Office &lt;/li&gt;        &lt;li&gt;Html Snippets &lt;/li&gt;        &lt;li&gt;Web Deploy &lt;/li&gt;        &lt;li&gt;Breakpoint Grouping &lt;/li&gt;        &lt;li&gt;Parallel Tasks Window &lt;/li&gt;        &lt;li&gt;Highlight References &lt;/li&gt;        &lt;li&gt;Call Hierarchy &lt;/li&gt;        &lt;li&gt;Historical Debugging &lt;/li&gt;        &lt;li&gt;Inline Call Tree &lt;/li&gt;        &lt;li&gt;Quick Search &lt;/li&gt;        &lt;li&gt;JQuery Intellisense &lt;/li&gt;        &lt;li&gt;Concurrency Profiler &lt;/li&gt;        &lt;li&gt;Breakpoint Import/Export &lt;/li&gt;        &lt;li&gt;Document Map Margin &lt;/li&gt;        &lt;li&gt;Parallel Stacks Window &lt;/li&gt;        &lt;li&gt;Improved Multi-Monitor &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Be in touch for more information regarding this release and other releases and don’t forget to see &lt;a href="http://channel9.msdn.com" target="_blank"&gt;Channel 9&lt;/a&gt; and the related &lt;a href="http://channel9.msdn.com/tags/vs2010/" target="_blank"&gt;Visual Studio 2010 Videos&lt;/a&gt; and also &lt;a href="http://channel9.msdn.com/tags/.NET+Framework+4.0/" target="_blank"&gt;.NET Framework 4.0&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Also check the &lt;a href="http://www.microsoft.com/downloads/details.aspx?DisplayLang=en&amp;amp;FamilyID=752cb725-969b-4732-a383-ed5740f02e93" target="_blank"&gt;Visual Studio 2010 Training Kit May Preview 2009&lt;/a&gt; that is also available for download.&lt;/p&gt;</description></item></channel></rss>