<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Jérôme Laban</title>
    <description>.NET Powered</description>
    <link>http://jaylee.org/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.Net Syndication Generator 1.0.0.0 (http://dotnetblogengine.net/)</generator>
    <language>en-US</language>
    <blogChannel:blogRoll>http://jaylee.org/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.jaylee.org/syndication.axd</blogChannel:blink>
    <dc:creator>Jérôme Laban</dc:creator>
    <dc:title>Jérôme Laban</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/JeromeLabanBlog" type="application/rss+xml" /><item>
      <title>WCF Streamed Transfers, IIS6 and IIS7 HTTP KeepAlive</title>
      <description>&lt;p&gt;
&lt;a href="http://blogs.codes-sources.com/jay/archive/2009/07/11/wcf-transferts-streamed-iis6-et-iis7-http-keepalive.aspx" target="_blank"&gt;&lt;em&gt;Ce billet est disponible en francais.&lt;/em&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
A while back, I was working on a client issue where I was having some kind of unusual socket exception from a WCF client connecting to an IIS6 hosted WCF service. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;To get a long story short, &lt;/strong&gt;&lt;strong&gt;if you&amp;#39;re using the .NET 3.5 WCF streamed transfer on IIS6 and making a lot of transfers in a small time, disable the KeepAlive feature on your web site. The performance will be lower, but it will last longer (without a client support call). &lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Still here with me ? :) If you have a bit more time to read, here some detail about what I found on this issue... 
&lt;/p&gt;
&lt;p&gt;
The setup is pretty simple : A WCF client that is sending a stream over a WCF service that has the transferMode set to streamed. This allows the transfer of a lot of information using genuine streaming, which means that the client writes to a System.IO.Stream instance, and the server reads from an other System.IO.Stream, and the data does not need to be transferred all at once, like in a &amp;quot;normal&amp;quot; SOAP communication. I&amp;#39;m using the required basicHttpBinding for both ends.
&lt;/p&gt;
&lt;p&gt;
The strange thing is that after having made more than 15000 requests to transfer streams,&amp;nbsp; I was receivig this exception :
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
	&lt;font face="courier new,courier"&gt;System.ServiceModel.CommunicationException: Could not connect to http://server/streamtest/StreamServiceTest.Service1.svc.&lt;br /&gt;
	TCP error code 10048: Only one usage of each socket address (protocol/network address/port) is normally permitted 10.0.0.1:80.&amp;nbsp; &lt;br /&gt;
	---&amp;gt; System.Net.WebException: Unable to connect to the remote server &lt;br /&gt;
	---&amp;gt; System.Net.Sockets.SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted 10.0.0.1:80&lt;/font&gt;
	&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
This is a rather common issue, which is mostly found where an application tries to bind to a TCP port but cannot do so, either because it is already being bound to an other application or because it does not use the SO_REUSEADDR socket option and the port was closed very recently.
&lt;/p&gt;
&lt;p&gt;
What is rather unusual is that this exception is raised on the client side and not on the server side !
&lt;/p&gt;
&lt;p&gt;
After a few netstat -an, I found out that an awful lot of sockets were lingering with the following state :
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
	&lt;font face="courier new,courier"&gt;TCP&amp;nbsp;&amp;nbsp;&amp;nbsp; the.client:50819&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the.server:80&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; TIME_WAIT&lt;/font&gt;
	&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
There were something like 15000 lines of this, with incrementing numbers for the local port. This state is normal, it&amp;#39;s meant to be that way, but it&amp;#39;s generally more found lingering on a server, much less on a client. 
&lt;/p&gt;
&lt;p&gt;
That could mean only one thing, considering that IIS6.0 is an HTTP/1.1 compliant web server: WCF is requesting that the connection to be closed at after a streamed transfer.
&lt;/p&gt;
&lt;p&gt;
Wireshark being my friend, I started looking up at the content of the dialog between IIS6 and my client application : 
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
	&lt;font face="courier new,courier"&gt;POST /streamtest/StreamServiceTest.Service1.svc HTTP/1.1&lt;br /&gt;
	MIME-Version: 1.0&lt;br /&gt;
	Content-Type: multipart/related; type=&amp;quot;application/xop+xml&amp;quot;;start=&amp;quot;&amp;lt;http://tempuri.org/0&amp;gt;&amp;quot;;boundary=&amp;quot;uuid:41d2cf74-aaa6-4a80-a6c4-0ec37692a437+id=1&amp;quot;;start-info=&amp;quot;text/xml&amp;quot;&lt;br /&gt;
	SOAPAction: &amp;quot;http://tempuri.org/IService1/Operation1&amp;quot;&lt;br /&gt;
	Host: the.server&lt;br /&gt;
	Transfer-Encoding: chunked&lt;br /&gt;
	Expect: 100-continue&lt;br /&gt;
	Connection: Keep-Alive&lt;/font&gt; 
	&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
The server answers this : 
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;p&gt;
	HTTP/1.1 100 Continue 
	&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&amp;nbsp;Then the stream transfer takes place, gets the SOAP response, then at the end :
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;font face="courier new,courier"&gt;HTTP/1.1 200 OK&lt;br /&gt;
	Date: Sat, 11 Jul 2009 01:40:16 GMT&lt;br /&gt;
	Server: Microsoft-IIS/6.0&lt;br /&gt;
	X-Powered-By: ASP.NET&lt;br /&gt;
	X-AspNet-Version: 2.0.50727&lt;br /&gt;
	Connection: close&lt;br /&gt;
	MIME-Version: 1.0&lt;br /&gt;
	Transfer-Encoding: chunked&lt;br /&gt;
	Cache-Control: private&lt;/font&gt;&lt;br /&gt;
&lt;/blockquote&gt;
&lt;p&gt;
I quickly found out that IIS6.0, or the WCF handler is forcing the connection to close on this last request. That&amp;#39;s not particularly unusual, since a server may explictly deny an HTTP client to keep alive the connection.
&lt;/p&gt;
&lt;p&gt;
What&amp;#39;s even more unusual is that out of luck by trying to deactivate the IIS6.0 keep alive setting on my web site, I noticed that all the connections were properly closed on the client...!
&lt;/p&gt;
&lt;p&gt;
I tried analysing a bit deeper the dialog between the client and the server, and I noticed two differences :
&lt;/p&gt;
&lt;ol&gt;
	&lt;li&gt;The content of the final answer of the IIS contains &lt;strong&gt;two &lt;/strong&gt;&amp;quot;Connection: close&amp;quot; headers, which could mean one by the WCF handler, and one by IIS itself. I&amp;#39;m not sure if repeating headers is forbidden in the RFC, I&amp;#39;d have to read it again to be sure.&lt;/li&gt;
	&lt;li&gt;It looks like the order of the FIN/ACK, ACK packets is a bit different, but I&amp;#39;m not sure either where that stands. Both the client and the server are sending FIN packets to the other side, probably the result of calling Socket.Close().&lt;br /&gt;
	&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
But then I found out something even stranger : It all works on IIS7 ! And the best of all, the KeepAlive status is honored by the web server. That obviously means that the global performance of the web service is better on IIS7 than it is on IIS6, since there is only one connection opened for all my 15000 calls, which is rather good. Too bad my client cannot switch to IIS7 for now...
&lt;/p&gt;
&lt;p&gt;
It also seems that the WCF client is not behaving the same way it does with IIS6, because at the TCP level only the client is sending a TCP FIN packet and the server is not when the keep alive is disabled.
&lt;/p&gt;
&lt;p&gt;
I think I&amp;#39;ll be posting this on Microsoft Connect soon, but I&amp;#39;m not sure where the problem lies, whether it is in IIS6, the WCF
client or the WCF server handler, but there is definitely an issue here. 
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/OQsekZx0pjE/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/07/WCF-Streamed-Transfers-IIS6-and-IIS7-HTTP-KeepAlive.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=ec3013cd-e684-4495-8cb8-126fcf75c481</guid>
      <pubDate>Fri, 10 Jul 2009 21:18:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=ec3013cd-e684-4495-8cb8-126fcf75c481</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=ec3013cd-e684-4495-8cb8-126fcf75c481</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/07/WCF-Streamed-Transfers-IIS6-and-IIS7-HTTP-KeepAlive.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=ec3013cd-e684-4495-8cb8-126fcf75c481</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=ec3013cd-e684-4495-8cb8-126fcf75c481</feedburner:origLink></item>
    <item>
      <title>Working with Bill Graziano's ClearTrace to optimize SQL queries</title>
      <description>&lt;p&gt;
&lt;a href="http://blogs.codes-sources.com/jay/archive/2009/05/27/outil-cleartrace-de-bill-graziano-pour-optimiser-des-requetes-sql.aspx"&gt;&lt;em&gt;Cet article est disponible en francais.&lt;/em&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
&lt;w:WordDocument&gt;
&lt;w:View&gt;Normal&lt;/w:View&gt;
&lt;w:Zoom&gt;0&lt;/w:Zoom&gt;
&lt;w:TrackMoves/&gt;
&lt;w:TrackFormatting/&gt;
&lt;w:PunctuationKerning/&gt;
&lt;w:ValidateAgainstSchemas/&gt;
&lt;w:SaveIfXMLInvalid&gt;false&lt;/w:SaveIfXMLInvalid&gt;
&lt;w:IgnoreMixedContent&gt;false&lt;/w:IgnoreMixedContent&gt;
&lt;w:AlwaysShowPlaceholderText&gt;false&lt;/w:AlwaysShowPlaceholderText&gt;
&lt;w:DoNotPromoteQF/&gt;
&lt;w:LidThemeOther&gt;EN-CA&lt;/w:LidThemeOther&gt;
&lt;w:LidThemeAsian&gt;X-NONE&lt;/w:LidThemeAsian&gt;
&lt;w:LidThemeComplexScript&gt;X-NONE&lt;/w:LidThemeComplexScript&gt;
&lt;w:Compatibility&gt;
&lt;w:BreakWrappedTables/&gt;
&lt;w:SnapToGridInCell/&gt;
&lt;w:WrapTextWithPunct/&gt;
&lt;w:UseAsianBreakRules/&gt;
&lt;w:DontGrowAutofit/&gt;
&lt;w:SplitPgBreakAndParaMark/&gt;
&lt;w:DontVertAlignCellWithSp/&gt;
&lt;w:DontBreakConstrainedForcedTables/&gt;
&lt;w:DontVertAlignInTxbx/&gt;
&lt;w:Word11KerningPairs/&gt;
&lt;w:CachedColBalance/&gt;
&lt;/w:Compatibility&gt;
&lt;w:BrowserLevel&gt;MicrosoftInternetExplorer4&lt;/w:BrowserLevel&gt;
&lt;m:mathPr&gt;
&lt;m:mathFont m:val="Cambria Math"/&gt;
&lt;m:brkBin m:val="before"/&gt;
&lt;m:brkBinSub m:val="&amp;#45;-"/&gt;
&lt;m:smallFrac m:val="off"/&gt;
&lt;m:dispDef/&gt;
&lt;m:lMargin m:val="0"/&gt;
&lt;m:rMargin m:val="0"/&gt;
&lt;m:defJc m:val="centerGroup"/&gt;
&lt;m:wrapIndent m:val="1440"/&gt;
&lt;m:intLim m:val="subSup"/&gt;
&lt;m:naryLim m:val="undOvr"/&gt;
&lt;/m:mathPr&gt;&lt;/w:WordDocument&gt;
&lt;/xml&gt;&lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt;&lt;xml&gt;
&lt;w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"
DefSemiHidden="true" DefQFormat="false" DefPriority="99"
LatentStyleCount="267"&gt;
&lt;w:LsdException Locked="false" Priority="0" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Normal"/&gt;
&lt;w:LsdException Locked="false" Priority="9" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="heading 1"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/&gt;
&lt;w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 1"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 2"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 3"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 4"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 5"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 6"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 7"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 8"/&gt;
&lt;w:LsdException Locked="false" Priority="39" Name="toc 9"/&gt;
&lt;w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/&gt;
&lt;w:LsdException Locked="false" Priority="10" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Title"/&gt;
&lt;w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/&gt;
&lt;w:LsdException Locked="false" Priority="11" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/&gt;
&lt;w:LsdException Locked="false" Priority="22" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Strong"/&gt;
&lt;w:LsdException Locked="false" Priority="20" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/&gt;
&lt;w:LsdException Locked="false" Priority="59" SemiHidden="false"
UnhideWhenUsed="false" Name="Table Grid"/&gt;
&lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/&gt;
&lt;w:LsdException Locked="false" Priority="1" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/&gt;
&lt;w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/&gt;
&lt;w:LsdException Locked="false" Priority="34" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/&gt;
&lt;w:LsdException Locked="false" Priority="29" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Quote"/&gt;
&lt;w:LsdException Locked="false" Priority="30" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/&gt;
&lt;w:LsdException Locked="false" Priority="60" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Shading Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="61" SemiHidden="false"
UnhideWhenUsed="false" Name="Light List Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="62" SemiHidden="false"
UnhideWhenUsed="false" Name="Light Grid Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="63" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="64" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="65" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="66" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="67" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="68" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="69" SemiHidden="false"
UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="70" SemiHidden="false"
UnhideWhenUsed="false" Name="Dark List Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="71" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="72" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful List Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="73" SemiHidden="false"
UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/&gt;
&lt;w:LsdException Locked="false" Priority="19" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/&gt;
&lt;w:LsdException Locked="false" Priority="21" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/&gt;
&lt;w:LsdException Locked="false" Priority="31" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/&gt;
&lt;w:LsdException Locked="false" Priority="32" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/&gt;
&lt;w:LsdException Locked="false" Priority="33" SemiHidden="false"
UnhideWhenUsed="false" QFormat="true" Name="Book Title"/&gt;
&lt;w:LsdException Locked="false" Priority="37" Name="Bibliography"/&gt;
&lt;w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/&gt;
&lt;/w:LatentStyles&gt;
&lt;/xml&gt;&lt;![endif]--&gt;
&lt;!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:0 0 0 0 0 0 0 0 0 0;
mso-font-charset:1;
mso-generic-font-family:roman;
mso-font-format:other;
mso-font-pitch:variable;
mso-font-signature:0 0 0 0 0 0;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;
mso-font-charset:0;
mso-generic-font-family:swiss;
mso-font-pitch:variable;
mso-font-signature:-520092929 1073786111 9 0 415 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-unhide:no;
mso-style-qformat:yes;
mso-style-parent:"";
margin-top:0cm;
margin-right:0cm;
margin-bottom:10.0pt;
margin-left:0cm;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-fareast-language:EN-US;}
.MsoChpDefault
{mso-style-type:export-only;
mso-default-props:yes;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:Calibri;
mso-fareast-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-fareast-language:EN-US;}
.MsoPapDefault
{mso-style-type:export-only;
margin-bottom:10.0pt;
line-height:115%;}
@page Section1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;
mso-header-margin:35.4pt;
mso-footer-margin:35.4pt;
mso-paper-source:0;}
div.Section1
{page:Section1;}
--&gt;
&lt;!--[if gte mso 10]&gt;
&lt;style&gt;
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin-top:0cm;
mso-para-margin-right:0cm;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0cm;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-fareast-language:EN-US;}
&lt;/style&gt;
&lt;![endif]--&gt;After listening to the &lt;a href="http://www.runasradio.com" title="RunAs Radio"&gt;RunAs Radio&lt;/a&gt; &lt;a href="http://www.runasradio.com/default.aspx?showNum=103" target="_blank" title="RunAs Radio - Bill Graziano on ClearTrace"&gt;show #103&lt;/a&gt; with &lt;a href="http://weblogs.sqlteam.com/billg/" title="Bill Graziano"&gt;Bill
Graziano&lt;/a&gt;, I decided to give a try to his tool, &lt;a href="http://www.cleardata.biz/cleartrace/download.aspx" target="_blank" title="ClearTrace"&gt;ClearTrace&lt;/a&gt;, an SQL trace
analysis tool.
&lt;/p&gt;
&lt;p&gt;
It turns out that I&amp;rsquo;m in an SQL optimization spree recently, and
the project I&amp;rsquo;m working on had an complete sequence of operations that took more
than 24 hours to complete. Analyzing traces with the SQL profiler can be time
consuming&amp;shy; - &amp;shy;&amp;shy;&amp;shy; needle in a haystack consuming - particularly when the log is over 7GB in size, in that case. 
&lt;/p&gt;
&lt;p&gt;
Finding small queries that are executed thousands of times is rather hard to track, and finding proper candidates for optimization is a
bit complex. You don&amp;#39;t want to spend time optimizing a query that has a small impact. 
&lt;/p&gt;
&lt;p&gt;
This is where Bill&amp;rsquo;s tool come into play. Give it a
trace file, the tool analyses it and gives you aggregate information about what
takes the most CPU/Duration/Read/Write. Pick your victim.
&lt;/p&gt;
&lt;p&gt;
After a few hours and a few runs of ClearTrace to find which
stored procedure needed rework, I found a bunch of store procedure that were executed thousands of time and that were using a lot of cumulative I/O. After optimizing these procedures, the whole process that took more than
24 hours is now down to about 7 hours.
&lt;/p&gt;
&lt;p&gt;
Nothing magic here, the key is to find what to optimize on
long running processes executing millions of queries. Bill&amp;rsquo;s tool does that
perfectly !
&lt;/p&gt;
&lt;p&gt;
On a side note, at first ClearTrace threw an out of memory
exception after trying to import my big trace file. Turns out that after
exporting it with &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank" title="Reflector"&gt;Reflector &lt;/a&gt;and debugging the code, I spotted a &lt;a href="http://weblogs.sqlteam.com/billg/archive/2009/05/27/ClearTrace-2008.34.aspx" target="_blank"&gt;small refactoring&lt;/a&gt;
issue that Bill fixed very quickly. Thanks Bill !
&lt;/p&gt;
&lt;p&gt;
As &lt;a href="http://www.dotnetrocks.com/" target="_blank"&gt;Carl Franklin&lt;/a&gt; says in .NET Rocks&amp;#39; &amp;ldquo;Better Know a Framework&amp;rdquo;,
learn it, use it, love it !
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/ejRvB6BB0pE/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/05/Working-with-Bill-Grazianos-ClearTrace-to-optimize-SQL-queries.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=e9d25a34-ba05-4b64-b858-133d0c45227c</guid>
      <pubDate>Wed, 27 May 2009 19:37:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=e9d25a34-ba05-4b64-b858-133d0c45227c</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=e9d25a34-ba05-4b64-b858-133d0c45227c</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/05/Working-with-Bill-Grazianos-ClearTrace-to-optimize-SQL-queries.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=e9d25a34-ba05-4b64-b858-133d0c45227c</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=e9d25a34-ba05-4b64-b858-133d0c45227c</feedburner:origLink></item>
    <item>
      <title>A C# Traverse extension method, with an F# detour</title>
      <description>&lt;p&gt;
&lt;em&gt;&lt;a href="http://blogs.codes-sources.com/jay/archive/2009/05/18/extension-method-traverse-et-un-detour-par-fsharp.aspx" target="_blank"&gt;Cet article est disponible en Fran&amp;ccedil;ais. &lt;/a&gt;&lt;/em&gt;
&lt;/p&gt;
&lt;h1&gt;The Traverse extension method in C# &lt;br /&gt;
&lt;/h1&gt;
&lt;p&gt;
Occasionally, you&amp;#39;ll come across data structures that take the form of single linked lists, like for instance the MethodInfo class and its GetBaseDefinition method.
&lt;/p&gt;
&lt;p&gt;
Let&amp;#39;s say for a virtual method you want, for a specific type, discover which overriden method in the hierarchy is marked with a specific attribute.
I assume in this example that the expected attribute is not inheritable. 
&lt;/p&gt;
&lt;p&gt;
You could implement it like this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MethodInfo GetTaggedMethod(MethodInfo info)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MethodInfo ret = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var attr = info.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;) &lt;span class="kwrd"&gt;as&lt;/span&gt; MyAttribute[];&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;if&lt;/span&gt; (attr.Length != 0)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;return&lt;/span&gt; info;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ret = info;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; info = info.GetBaseDefinition();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;while&lt;/span&gt; (ret != info);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
This method has two states variables and a loop, which makes it a bit harder to stabilize. This is a method that could easily be expressed as a LINQ query, but (as far as I know) there is no way to make a enumeration of a data structure which is part of a linked list.
&lt;/p&gt;
&lt;p&gt;
To be able to do this, which is &amp;quot;traverse&amp;quot; a list of objects of the same type that are linked from one to the next, an extension method containing a generic iterator can be written like this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Extensions&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;T&amp;gt; Traverse&amp;lt;T&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; T source, Func&amp;lt;T, T&amp;gt; next)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;while&lt;/span&gt; (source != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;yield&lt;/span&gt; &lt;span class="kwrd"&gt;return&lt;/span&gt; source;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; source = next(source);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
This is a really simple iterator method, which calls a method to get the next element using the current element and stops if the next value is null.
&lt;/p&gt;
&lt;p&gt;
It can be used easily like this, using the GetBaseDefinition example :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp; var methodInfo = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Dummy).GetMethod(&amp;quot;Foo&amp;quot;); 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp; IEnumerable&amp;lt;MethodInfo&amp;gt; methods = methodInfo.Traverse(m =&amp;gt; m != m.GetBaseDefinition() ? m.GetBaseDefinition() : &lt;span class="kwrd"&gt;null&lt;/span&gt;);
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
Just to be precise, the lambda is not exactly perfect, as it is calling GetBaseDefinition twice. It can definitely be optimised a bit.
&lt;/p&gt;
&lt;p&gt;
Anyway, to go back at the first example, the GetTaggedMethod function can be written as a single LINQ query, using the Traverse extension :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MethodInfo GetTaggedMethod(MethodInfo info)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var methods = from m &lt;span class="kwrd"&gt;in&lt;/span&gt; methodInfo.Traverse(m =&amp;gt; m != m.GetBaseDefinition() ? m.GetBaseDefinition() : &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; let attributes = m.GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(MyAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;where&lt;/span&gt; attributes.Length != 0&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select m;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;return&lt;/span&gt; methods.FirstOrDefault();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
I, for one, find this code more readable... But this is a question of taste :)
&lt;/p&gt;
&lt;p&gt;
Nonetheless, the MethodInfo linked-list is not the perfect example, because the end of the chain is not a null reference but rather the same method we&amp;#39;re testing. Most of the time, a chain will end with a null, which is why the Traverse method uses null to end the enumeration. I&amp;#39;ve been using this method to perform queries on a hierarchy of objects that have parent objects of the same type, and the parent&amp;#39;s root set to null. It has proven to be quite useful and concise when used in a LINQ query.
&lt;/p&gt;
&lt;h1&gt;An F# Detour &lt;br /&gt;
&lt;/h1&gt;
&lt;p&gt;
As I was here, I also tried to find out what an F# version of this code would be. So, with the help of recursive functions, I came up with this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
let rec traverse(m, n) =&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; let next = n(m)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;if&lt;/span&gt; next = &lt;span class="kwrd"&gt;null&lt;/span&gt; then&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; [m] &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; [m] @ traverse(next, n)
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
The interesting part here is that F# does not require to specify any type. &amp;quot;m&amp;quot; is actually an object, and &amp;quot;n&amp;quot; a (obj -&amp;gt; obj) function, but returns a list of objects. And it&amp;#39;s used like this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
let testMethod = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;&amp;lt;Dummy&amp;gt;.GetMethod(&amp;quot;Foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;span class="kwrd"&gt;for&lt;/span&gt; m &lt;span class="kwrd"&gt;in&lt;/span&gt;&amp;nbsp; traverse(testMethod, fun x -&amp;gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; x = x.GetBaseDefinition() then &lt;span class="kwrd"&gt;null&lt;/span&gt; &lt;span class="kwrd"&gt;else&lt;/span&gt; x.GetBaseDefinition()) &lt;span class="kwrd"&gt;do&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Printf.printfn &amp;quot;%s.%s&amp;quot; m.DeclaringType.Name m.Name
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
Actually, the F# traverse method is not exactly like the C# traverse method, because it is not an extension method, and it is not lazily evaluated. It is also a bit more verbose, mainly because I did not find an equivalent of the ternary operator &amp;quot;?:&amp;quot;. 
&lt;/p&gt;
&lt;p&gt;
After digging a bit in the F# language spec, I found out it exists an somehow equivalent to the yield keyword. It is used like this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;
let rec traverse(m, n) =&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; seq {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; let next = n(m)&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;if&lt;/span&gt; next = &lt;span class="kwrd"&gt;null&lt;/span&gt; then&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;yield&lt;/span&gt; m&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;yield&lt;/span&gt; m&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;yield&lt;/span&gt;! traverse(next, n)&lt;br /&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;
It is used the same way, but the return value is not a list anymore but a sequence.
&lt;/p&gt;
&lt;p&gt;
I also find interesting that F# is able to return tuples out of the box, and for my attribute lookup, I&amp;#39;d have the method and I&amp;#39;ll also have the attribute instance that has been found. Umbrella also defines tuples useable from C#, but it&amp;#39;s an addon. 
&lt;/p&gt;
&lt;p&gt;
F# is getting more and more interesting as I dig into its features and capabilities... 
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/jTgl_CWY9Uw/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/05/A-csharp-Traverse-extension-method-with-an-Fsharp-detour.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=1dce6c1e-5bf3-4755-88d0-0e9c2e99a6ae</guid>
      <pubDate>Sun, 17 May 2009 09:10:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=1dce6c1e-5bf3-4755-88d0-0e9c2e99a6ae</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=1dce6c1e-5bf3-4755-88d0-0e9c2e99a6ae</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/05/A-csharp-Traverse-extension-method-with-an-Fsharp-detour.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=1dce6c1e-5bf3-4755-88d0-0e9c2e99a6ae</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=1dce6c1e-5bf3-4755-88d0-0e9c2e99a6ae</feedburner:origLink></item>
    <item>
      <title>Hyper-V Virtual Machine Mover 1.0.2.0</title>
      <description>&lt;p&gt;
Thanks to the guys at &lt;a href="http://jaylee.org/admin/Pages/www.lakecomm.com"&gt;Lakewood Communications&lt;/a&gt;, I&amp;#39;ve updated my tool to move Hyper-V Virtual Machines to allow VMs that do not have any snapshots.
&lt;/p&gt;
&lt;p&gt;
Version 1.0.2.0 also has a minor fix to try guessing the original VM path to replace it correctly in the configuration file. That would mean that you could have detached a VM and could not have attached it back.
&lt;/p&gt;
&lt;p&gt;
On the Win2008 R2 front now the RC is out, for the time being since I don&amp;#39;t have any spare hardware to test it on, I don&amp;#39;t know if it works or if it still needed. If you do have tested my tool on this OS, please let me know. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://jaylee.org/page/Hyper-V-Virtual-Machine-Mover.aspx"&gt;Download the latest version here.&lt;/a&gt;
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/ryNwDl-m_DU/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/05/Hyper-V-Virtual-Machine-Mover-v1020.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=dd597844-f487-436d-a755-51befadd62ef</guid>
      <pubDate>Sun, 10 May 2009 15:20:00 -0700</pubDate>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=dd597844-f487-436d-a755-51befadd62ef</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=dd597844-f487-436d-a755-51befadd62ef</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/05/Hyper-V-Virtual-Machine-Mover-v1020.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=dd597844-f487-436d-a755-51befadd62ef</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=dd597844-f487-436d-a755-51befadd62ef</feedburner:origLink></item>
    <item>
      <title>SharePoint : The database connection string is not available. (0xc0041228)</title>
      <description>&lt;p&gt;
A Sharepoint Services 3.0 setup I&amp;#39;m managing had a few issues lately, and I had to bring back up an old version of the system. The original setup had a Search Server Express 2008 installed, and the backup I restored did not, even though I had the databases for it. 
&lt;/p&gt;
&lt;p&gt;
After reinstalling everything that was needed, and having the Search Server properly indexing content, I kept having a lot of messages like&lt;font face="courier new,courier"&gt; &amp;quot;The database connection string is not available.&amp;quot;&lt;/font&gt; in the event log, and&lt;font face="courier new,courier"&gt; &amp;quot;Your search cannot be completed because of a service error.&amp;quot;&lt;/font&gt; in the search tool in any Sharepoint site. I had the content database properly associated with the correct indexer.
&lt;/p&gt;
&lt;p&gt;
I did not notice at first that the service named &amp;quot;Windows SharePoint Services Search&amp;quot; was not started, and when I tried to start it, I had a nice &lt;font face="courier new,courier"&gt;&amp;quot;The handle is invalid.&amp;quot;&lt;/font&gt; error message... Not very helpful.
&lt;/p&gt;
&lt;p&gt;
A few posts around the web were suggesting to stop that service, then restart it. One suggested to check the user account of that service, which was &amp;quot;Network Service&amp;quot; for me. I changed it to the same domain account that the &amp;quot;Windows SharePoint Services Timer&amp;quot; service is using. At this point, the service was starting properly, but I was still having the&lt;font face="courier new,courier"&gt; &amp;quot;The database connection string is not available.&amp;quot;&lt;/font&gt; message.
&lt;/p&gt;
&lt;p&gt;
In the &amp;quot;Services on Server&amp;quot;, I tried stopping the &amp;quot;Windows SharePoint Services Search&amp;quot; service, (telling me that it was going to delete the index content), which succeeded. But trying to restart the service gave me an error saying that the database already had content, and that I had to create a new one.
&lt;/p&gt;
&lt;p&gt;
I did create a new database, but the service would still not start, this time giving an other error message that I enjoy so much : &lt;font face="courier new,courier"&gt;&amp;quot;An unknown problem occured&amp;quot;&lt;/font&gt;.
&lt;/p&gt;
&lt;p&gt;
I went back to some forum posts, and I came across a command to &amp;quot;initialize&amp;quot; the service from the command line with STSADM :
&lt;/p&gt;
&lt;p&gt;
&lt;font face="courier new,courier"&gt;&amp;nbsp;stsadm -o spsearch -action start -farmserviceaccount [domain_account] -farmservicepassword [domain_account_password]&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Which at first gave me this :
&lt;/p&gt;
&lt;p&gt;
&lt;font face="courier new,courier"&gt;&amp;nbsp;The specified database has an incorrect collation.&amp;nbsp; Rebuild the database with the Latin1_General_CI_AS_KS_WS collation or create a new database.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
I did re-create the database with the proper collation, then ran stsadm again and it gave me this :&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="courier new,courier"&gt;&amp;nbsp;The Windows SharePoint Services Search service was successfully started.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Hurray ! That did the trick, and indeed, my searches in any Sharepoint sites were not returing any error. I just had to wait for the service to refresh its index, and my search was running again !
&lt;/p&gt;
&lt;p&gt;
This is a long and verbose post, but I hope this will help someone with this cryptic message... 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/BwaA_RCbN2k/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/03/Sharepoint--The-database-connection-string-is-not-available-(0xc0041228).aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=66c93caa-a3df-41e7-a5af-ad0b759fb00e</guid>
      <pubDate>Tue, 31 Mar 2009 20:21:00 -0700</pubDate>
      <category>Sharepoint</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=66c93caa-a3df-41e7-a5af-ad0b759fb00e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=66c93caa-a3df-41e7-a5af-ad0b759fb00e</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/03/Sharepoint--The-database-connection-string-is-not-available-(0xc0041228).aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=66c93caa-a3df-41e7-a5af-ad0b759fb00e</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=66c93caa-a3df-41e7-a5af-ad0b759fb00e</feedburner:origLink></item>
    <item>
      <title>Hyper-V Virtual Machine Mover and Hyper-V Server</title>
      <description>&lt;p&gt;
I&amp;#39;ve had some hardware trouble lately, with hard-drives failing with some VMs on these, and my Hyper-V Mover tool hase saved me a great deal of time. 
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ve had some time to improve it and this time, it is possible to attach and detach VMs from remote machines, and particularly those that are on Hyper-V Server machines.
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ve created a page for this tool, the &lt;a href="http://jaylee.org/page/Hyper-V-Virtual-Machine-Mover.aspx"&gt;Hyper-V Virtual Machine Mover&lt;/a&gt;, version 1.0.1.0.
&lt;/p&gt;
&lt;p&gt;
Still no sources available but they&amp;#39;ll be available on CodePlex soon. 
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/Z1YfsUdSRcM/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/03/Hyper-V-Virtual-Machine-Mover-and-Hyper-V-Server.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=74d678af-dc1c-46c2-bbfa-e72ff93ae48d</guid>
      <pubDate>Sat, 28 Mar 2009 14:47:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=74d678af-dc1c-46c2-bbfa-e72ff93ae48d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=74d678af-dc1c-46c2-bbfa-e72ff93ae48d</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/03/Hyper-V-Virtual-Machine-Mover-and-Hyper-V-Server.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=74d678af-dc1c-46c2-bbfa-e72ff93ae48d</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=74d678af-dc1c-46c2-bbfa-e72ff93ae48d</feedburner:origLink></item>
    <item>
      <title>Google Transit and Montreal's STM</title>
      <description>&lt;p&gt;
A while ago, the Montr&amp;eacute;al&amp;#39;s STM transit system &lt;a href="http://blog.fagstein.com/2008/10/24/google-transit-includes-stm-buses-metro/"&gt;announced&lt;/a&gt; that they were now supported by Google Transit.
&lt;/p&gt;
&lt;p&gt;
While it is possible to trace proper routes, Google&amp;#39;s having the same problem as I do, which is that the STM is updating schedules per trimester. And since it&amp;#39;s the STM that is providing the data and that it&amp;#39;s not been updated since the 1st of January 2009, schedules have been incorrect ever since.
&lt;/p&gt;
&lt;p&gt;
To be perfectly fair, I did not update the schedules in &lt;a href="http://www.jaylee.org/stm"&gt;my application&lt;/a&gt; since that time too by lack of time to create a proper update procedure, but I&amp;#39;m not paid for that either... 
&lt;/p&gt;
&lt;p&gt;
Now that I&amp;#39;ve given it some thoughts, I&amp;#39;m now streamlining the schedule updates stops after stops as long as they are out of date. Previously, I updated the database all at once, but this does not scale... Now the updates are progressive, which is far more manageable for me.
&lt;/p&gt;
&lt;p&gt;
Anyway, now there may be a simple message saying that the displayed schedule is outdated, which is better than trusting the time and blaming the STM for no reason :) 
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/uR1UwCeVhFE/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/03/Google-Transit-and-Montreals-STM.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=6e5d82d7-460d-4fef-9ad0-efc2ba16be3a</guid>
      <pubDate>Sun, 15 Mar 2009 21:53:00 -0700</pubDate>
      <category>.NET</category>
      <category>Bus Stop Locator</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=6e5d82d7-460d-4fef-9ad0-efc2ba16be3a</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=6e5d82d7-460d-4fef-9ad0-efc2ba16be3a</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/03/Google-Transit-and-Montreals-STM.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=6e5d82d7-460d-4fef-9ad0-efc2ba16be3a</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=6e5d82d7-460d-4fef-9ad0-efc2ba16be3a</feedburner:origLink></item>
    <item>
      <title>A tool to move an Hyper-V Virtual Machine without exporting it</title>
      <description>&lt;p&gt;
&lt;em&gt;Cet article est disponible &lt;a href="http://blogs.codes-sources.com/jay/archive/2009/02/19/outil-pour-d-placer-une-vm-hyper-v-sans-l-exporter.aspx" target="_blank"&gt;en francais&lt;/a&gt;.&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Hyper-V is a wonderful tool, and provides great performance and stability. But on the administration side, available tools are a bit scare, and even though most general operations are available, some are a bit hard to use. One can guess that this will improve in Windows Server 2008 R2. 
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
But for now, the administration tools do not provide any mean to import a VM that has not been previously exported. Exporting a VM can only be done on the original host server while it is still running. In the case of a crashed server, exporting a VM becomes a bit more complex.
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Some techniques do exist, &lt;a href="http://blogs.msdn.com/robertvi/archive/2008/12/19/howto-manually-add-a-vm-configuration-to-hyper-v.aspx"&gt;here &lt;/a&gt;and &lt;a href="http://www.adopenstatic.com/cs/blogs/ken/archive/2008/01/14/15467.aspx"&gt;there&lt;/a&gt;, that explain by means of mklink and icacls, &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;how to recreate symbolic links and file permissions for the VM configuration files. But that stays a particularly complex task, mostly because all files must be modified, and a specific order must be respected for all modifications. And this is especially true for the case of a running host server.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
After having dug in Hyper-V &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;symlinks and WMI interface, I created a GUI tool that allows to attach and detach VM that have not been previously epoxted.&lt;br /&gt;
&lt;br /&gt;
Some thougts on this tool : &lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;A VM can only be detached if it is in the &amp;quot;Saved&amp;quot; or &amp;quot;Stopped&amp;quot; state.&lt;/font&gt;&lt;/li&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;It is not necessary to stop the Hyper-V service and all modifications are detected live by the service.&lt;/font&gt;&lt;/li&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;A VM can only be imported if it contains at least on HDD on the IDE 0 controller.&lt;/font&gt;&lt;/li&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;All the VM files must be under the same directory, HDD and snapshots.&lt;/font&gt;&lt;/li&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;All files that are modified are backed-up next to the original files; All other files are not modified nor moved.&lt;/font&gt;&lt;/li&gt;
	&lt;li&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;.NET 3.5 must be installed.&lt;br /&gt;
	&lt;/font&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;I&amp;#39;ll provide the sources for this tool in a near future, as well as a console version.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Of course, there will be bugs, and do not hesitate to report them to me. I may not be able to do anything about it because it is a tool that performs a operation that is (I assume) not supported by Microsoft. &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
&lt;br /&gt;
You can download the tool &lt;a href="http://jaylee.org/files/VMMove-1.0.0.0.zip"&gt;here&lt;/a&gt;.&lt;/font&gt;
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/JRNnlBt1Kyk/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2009/02/A-tool-to-move-an-Hyper-V-Virtual-Machine-without-exporting-it.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=6270c420-db5e-4a4a-9009-bff6829ce920</guid>
      <pubDate>Fri, 20 Feb 2009 20:26:00 -0700</pubDate>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=6270c420-db5e-4a4a-9009-bff6829ce920</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=6270c420-db5e-4a4a-9009-bff6829ce920</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2009/02/A-tool-to-move-an-Hyper-V-Virtual-Machine-without-exporting-it.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=6270c420-db5e-4a4a-9009-bff6829ce920</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=6270c420-db5e-4a4a-9009-bff6829ce920</feedburner:origLink></item>
    <item>
      <title>Using Multiple Where Clauses in a LINQ Query</title>
      <description>&lt;div align="justify"&gt;
&lt;em&gt;Cet article est &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/12/06/utiliser-plusieurs-clauses-where-dans-une-requete-linq.aspx" target="_blank" title="Utiliser plusieurs clauses Where dans une requ&amp;ecirc;te LINQ - Jerome Laban"&gt;disponible en francais&lt;/a&gt;.&lt;/em&gt; &lt;br /&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;After writing my &lt;a href="http://jaylee.org/post/2008/12/fsharp-TryWith-Maybe-and-Umbrella.aspx" target="_blank" title="F#, TryWith, Maybe and Umbrella - Jerome Laban"&gt;previous article&lt;/a&gt; where I needed to intercept exceptions in a LINQ Query, I found out that it is possible to specify multiple where clauses in a LINQ Query.&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
Here is the query :&lt;br /&gt;
&lt;/font&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

var q = from file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(@&amp;quot;C:\Windows\Microsoft.NET\Framework\v2.0.50727&amp;quot;, &amp;quot;*.dll&amp;quot;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    let asm = file.TryWith(f =&amp;gt; Assembly.LoadFile(f))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    &lt;span class="kwrd"&gt;where&lt;/span&gt; asm != &lt;span class="kwrd"&gt;null&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    let types = asm.TryWith(a =&amp;gt; a.GetTypes(), (Exception e) =&amp;gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; Type[0])&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;where&lt;/span&gt; types.Any()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    select &lt;span class="kwrd"&gt;new&lt;/span&gt; { asm, types };&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
&lt;/font&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;This query is able to find assemblies for which it is possible to list types. The point of using multiple Where clauses is to avoir evaluating chunks of a query if previous chunks can prevent it. By the way, the TryWith around the Assembly.GetTypes() is there to intercept exceptions raised when loading types, in case dependencies would not be available at the moment of the enumeration.&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
A useful LINQ trick to remember !&lt;/font&gt;
&lt;/div&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/AoWXK6vzHKA/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/12/Using-Multiple-Where-Clauses-in-a-LINQ-Query.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=e78fadc9-83ee-4e42-9e98-29c6be38c840</guid>
      <pubDate>Sat, 06 Dec 2008 15:32:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=e78fadc9-83ee-4e42-9e98-29c6be38c840</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=e78fadc9-83ee-4e42-9e98-29c6be38c840</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/12/Using-Multiple-Where-Clauses-in-a-LINQ-Query.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=e78fadc9-83ee-4e42-9e98-29c6be38c840</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=e78fadc9-83ee-4e42-9e98-29c6be38c840</feedburner:origLink></item>
    <item>
      <title>F#, TryWith, Maybe and Umbrella</title>
      <description>&lt;div align="justify"&gt;
&lt;em&gt;Cet article est &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/12/06/fsharp-trywith-maybe-et-umbrella.aspx" target="_blank" title="F#, TryWith, Maybe et Umbrella"&gt;disponible en Fran&amp;ccedil;ais&lt;/a&gt;.&lt;/em&gt; &lt;br /&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;I&amp;#39;ve thrown myself a bit in the discovery of F#, and even though I do not intend to make it my first language, I intend to use techniques and features found in it and try to port them into C#. New additions in C# 3.0 make it a good target for functional concepts.&lt;br /&gt;
&lt;br /&gt;
There seem to be a consensus for the fact that F# is not a multi-purpose language, as C# is also not, for instance with the writing of parallel code. C# is not a perfect language for this, but F# seems to be. At the opposite, F# does not seem to be a language of choice for writing GUI code. For my part, and considering that F# if not really official, reusing concepts will be enough for now.&lt;/font&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;h3 align="justify"&gt;TryWith Extension&lt;/h3&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Using F#, I had to write this:
&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;        let AllValidAssemblies = [&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;for&lt;/span&gt; file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(@&amp;quot;C:\Windows\Microsoft.NET\Framework\v2.0.50727&amp;quot;, &amp;quot;*.dll&amp;quot;) -&amp;gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp; System.Reflection.Assembly.LoadFile(file)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        ]&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;This code creates a list of assemblies that can be loaded in the current AppDomain. There is however an issue with the invocation of the Assembly.LoadFile method, because it raises an exception when the file is not loadable for some reason. This is a non-modifiable behavior, even though we would like to return a null instead of an exception.
&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
To work around this, there is a feature in F# that can do this :&lt;br /&gt;
&lt;/font&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;        let EnumAllTypes = [&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;for&lt;/span&gt; file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(@&amp;quot;C:\Windows\Microsoft.NET\Framework\v2.0.50727&amp;quot;, &amp;quot;*.dll&amp;quot;) -&amp;gt; &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;try&lt;/span&gt; System.Reflection.Assembly.LoadFile(file) with _ -&amp;gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        ]&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;The point of the try/with block is to transform any exception into a null reference.
&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
To transpose the creation of this list in C# with a LINQ query, the same problem arises. We must intercept the exception raised by LoadFile and convert it to a null reference.&lt;br /&gt;
&lt;br /&gt;
Here is the equivalent in C#, without the exception handling :
&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;            var q = from file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(@&amp;quot;C:\Windows\Microsoft.NET\Framework\v2.0.50727&amp;quot;, &amp;quot;*.dll&amp;quot;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    let asm = Assembly.LoadFile(file)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select asm;&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;When LoadFile raises an exception, the execution of the request is interrupted, which is a problem.
&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Extension Methods can be of a great value here, and even though a normal method could do the trick, we can write this :&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Extensions&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; TResult TryWith&amp;lt;TInstance, TResult&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt; TInstance instance, Func&amp;lt;TInstance, TResult&amp;gt; action)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;try&lt;/span&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; action(instance);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;catch&lt;/span&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;default&lt;/span&gt;(TResult);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
The idea behind this method is to reproduce the behavior of the try/with F# construct. With this method, we can update the LINQ query into this :&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;            var q = from file &lt;span class="kwrd"&gt;in&lt;/span&gt; Directory.GetFiles(@&amp;quot;C:\Windows\Microsoft.NET\Framework\v2.0.50727&amp;quot;, &amp;quot;*.dll&amp;quot;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    let asm = file.TryWith(f =&amp;gt; Assembly.LoadFile(f))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select asm;&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;This is creates the same list the F# code does, with null references for assemblies that could not be loaded.&lt;br /&gt;
&lt;br /&gt;
The TryWith method can be overloaded to be a bit more flexible, like calling a method for a specific exception :&lt;/font&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; TResult TryWith&amp;lt;TInstance, TResult, TException&amp;gt;(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;this&lt;/span&gt; TInstance instance, Func&amp;lt;TInstance, TResult&amp;gt; action, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                Func&amp;lt;TException, TResult&amp;gt; exceptionHandler&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;where&lt;/span&gt; TException : Exception&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;try&lt;/span&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; action(instance);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;catch&lt;/span&gt; (TException e) {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; exceptionHandler(e);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;catch&lt;/span&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;default&lt;/span&gt;(TResult);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        &amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;By the way, there is an interesting bug with this code. If we execute this :&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp; &amp;nbsp; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            var res = &lt;span class="kwrd"&gt;value&lt;/span&gt;.TryWith(s =&amp;gt; s.ToString(), (Exception e) =&amp;gt; &amp;quot;Exception&amp;quot;);&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;The behavior is different depending on whether it is executed with or without the debugger with the x86 runtime. It seems that the code generator &amp;quot;forgets&amp;quot; to add the handler for the TException typed exception, which is annoying. This is not a big bug, mainly because it only appears when the x86 debugger is present. With the x64 runtime debugger, there is no problem though. For those interesting in this, &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=386652" title="Microsoft Connect"&gt;the bug is on Connect&lt;/a&gt;.&lt;/font&gt;&lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;h3 align="justify"&gt;Maybe Extension&lt;br /&gt;
&lt;/h3&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;I also added recently in &lt;a href="http://www.codeplex.com/umbrella" target="_blank" title="Umbrella - CodePlex"&gt;Umbrella&lt;/a&gt; an extension named Maybe, which has a behavior rather similar to TryWith, but without the exceptions :&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; TResult Maybe&amp;lt;TResult, TInstance&amp;gt;(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;this&lt;/span&gt; TInstance instance, &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Func&amp;lt;TInstance, TResult&amp;gt; function)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;return&lt;/span&gt; instance == &lt;span class="kwrd"&gt;null&lt;/span&gt; ? &lt;span class="kwrd"&gt;default&lt;/span&gt;(TResult) : function(instance);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;The point of this method is to be able to execute code if the original value is not null. For instance :&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;object&lt;/span&gt; instance = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            Console.WriteLine(&amp;quot;{0}&amp;quot;, instance.Maybe(o =&amp;gt; o.GetType());&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;This allows the evaluation of the GetType call, only if &amp;quot;instance&amp;quot; is not null. With a method call like this, it is possible to write an &amp;quot;if&amp;quot; block, with inside a LINQ query, this because a bit more complex.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;The idea for the code is not new and is similar to the functional Monad concept. It has been covered numerous times, and an implementation more in line with F# can be found on &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/10/13/functional-net-linq-or-language-integrated-monads.aspx" title="Functional .NET - LINQ or Language Integrated Monads? "&gt;Matthew Podwysocki&amp;#39;s Blog&lt;/a&gt;&lt;/font&gt;.
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;h3 align="justify"&gt;Pollution ?&lt;/h3&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;When we&amp;#39;re talking about pollution linked to Extension Methods, we&amp;#39;re talking about Intellisense pollution. We can quickly find ourselves dealing with a bunch of extensions that are useful in the context of the current code, which renders Intellisense unusable. With Umbrella, these two extensions are somehow polluting all types, because they are generic without constraints.&lt;br /&gt;
&lt;br /&gt;
Although these are only two very generic extensions, this can apply to almost any block of code, but they could find themselves better placed in an Umbrella Extension Point, rather than directly on every types.&lt;br /&gt;
&lt;br /&gt;
We could have this :&lt;/font&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;object&lt;/span&gt; instance = &lt;span class="kwrd"&gt;null&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            Console.WriteLine(&amp;quot;{0}&amp;quot;, instance.Control().Maybe(o =&amp;gt; o.GetType());&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;But I have some issues with this approach : To be able to create an extension point the Control methd has to create an instance of the IExtensionPoint. This add a new instantiation during the execution, although the lambda also creates itself a hidden instance, we&amp;#39;re counting anymore... There is also the fact that it lengthens the code line, but is only aesthetics. We&amp;#39;ll see what pops out ...&lt;br /&gt;
&lt;br /&gt;
Anyway, it is interesting to see the impact the learning a new language has on the style of writing code with another language that one&amp;#39;s been using for a long time...
&lt;/font&gt;
&lt;/div&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/9GCfPnw17LU/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/12/fsharp-TryWith-Maybe-and-Umbrella.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=3e9ec70a-687e-4ca7-8f62-80b05ddf9d96</guid>
      <pubDate>Sat, 06 Dec 2008 13:49:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=3e9ec70a-687e-4ca7-8f62-80b05ddf9d96</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=3e9ec70a-687e-4ca7-8f62-80b05ddf9d96</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/12/fsharp-TryWith-Maybe-and-Umbrella.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=3e9ec70a-687e-4ca7-8f62-80b05ddf9d96</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=3e9ec70a-687e-4ca7-8f62-80b05ddf9d96</feedburner:origLink></item>
    <item>
      <title>Local Variables in Lambda Expressions</title>
      <description>&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;em&gt;Cet article est &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/11/21/variables-locales-et-expressions-lambda.aspx" target="_blank" title="Variables Locales et Expressions Lambda"&gt;disponible en fran&amp;ccedil;ais&lt;/a&gt;. &lt;/em&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&amp;nbsp;
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
After a quick chat with &lt;a href="http://blogs.msdn.com/ericlippert/" target="_blank" title="Eric Lippert"&gt;Eric Lippert&lt;/a&gt; about a &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/11/19/expressions-lambda-et-boucles-foreach.aspx" target="_blank" title="Expressions Lambda et Boucles ForEach - Jerome Laban"&gt;post&lt;/a&gt;&amp;nbsp; on the use in lambda expressions of a local variable declared in a foreach loop, Eric pointed me out that this piece of code :&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    Action action = () =&amp;gt; Console.WriteLine(a);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    action();
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;/p&gt;
&lt;div align="justify"&gt;
&amp;nbsp;&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Is actually not expanded by the compiler to this code :&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CompilerGenerated]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; a;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; &amp;lt;Main&amp;gt;b__0()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;          Console.WriteLine(&lt;span class="kwrd"&gt;this&lt;/span&gt;.a);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;void&lt;/span&gt; Main()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            var display = &lt;span class="kwrd"&gt;new&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass1();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; display.a = a;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var action = &lt;span class="kwrd"&gt;new&lt;/span&gt; Action(display.&amp;lt;Main&amp;gt;b__0);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;            action();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&amp;nbsp;
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
I made the assumption that a local variable was simply copied in the &amp;quot;DisplayClass&amp;quot; if it is not used after the creation of the lambda, which&amp;nbsp; is not the case.
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
If we take this slightly different sample :
&lt;/font&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;      &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    Action action = () =&amp;gt; Console.WriteLine(a);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    a = 42;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    action();
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;My assumption would have made this code display &amp;quot;0&amp;quot;. This is correct because lambda expressions (and anonymous methods) &amp;quot;capture&amp;quot; the variable and not the value; The execution must display 42.
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
Actually, this latter piece of code is expanded like this:&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;     var display = &lt;span class="kwrd"&gt;new&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass1();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    display.a = 0;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var action = &lt;span class="kwrd"&gt;new&lt;/span&gt; Action(display.&amp;lt;Main&amp;gt;b__0);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    display.a = 42;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    action();
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;We can see that in fact, the variable that was previously local, on the stack, has been &amp;quot;promoted&amp;quot; as a field memberr of the &amp;quot;Display Class&amp;quot;. This means that all references to this &amp;quot;local&amp;quot; variable, inside or outside of the lambda, are replaced to point to the current instanc e of the &amp;quot;DisplayClass&amp;quot;.
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
This is quite simple actually, but we can feel that the &amp;quot;magic&amp;quot; behind the C# 3.0 syntactic sugar is the result of a lot of thinking !
&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;br /&gt;
I will end this post by a big thanks to Eric Lippert, who took the time to answer me, even though he&amp;#39;s probably under heavy load with the developement of C# 4.0. (With the contravariance of generics, yey !)
&lt;/font&gt;
&lt;/div&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal"&gt;&lt;/span&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/hy2vtdq6PQM/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/11/Local-Variables-in-Lambda-Expressions.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=d7dffe52-fcd7-4f22-8d54-03df65944075</guid>
      <pubDate>Thu, 20 Nov 2008 19:58:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=d7dffe52-fcd7-4f22-8d54-03df65944075</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=d7dffe52-fcd7-4f22-8d54-03df65944075</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/11/Local-Variables-in-Lambda-Expressions.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=d7dffe52-fcd7-4f22-8d54-03df65944075</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=d7dffe52-fcd7-4f22-8d54-03df65944075</feedburner:origLink></item>
    <item>
      <title>Lambda Expression and ForEach loops</title>
      <description>&lt;p&gt;
&lt;em&gt;Cet article est &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/11/19/expressions-lambda-et-boucles-foreach.aspx" target="_blank" title="Expressions Lambda et boucles ForEach"&gt;disponible en fran&amp;ccedil;ais&lt;/a&gt;. &lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
To enhance the performances of a type serializer, and to use a small extension that I recently wrote for &lt;a href="http://www.codeplex.com/umbrella" target="_blank" title="Umbrella - Codeplex"&gt;Umbrella&lt;/a&gt; I stumbled upon an interesting small &amp;quot;Side Effect&amp;quot; seen when creating lambda expressions inside a foreach loop.
&lt;/p&gt;
&lt;p&gt;
Let&amp;#39;s take this simple piece of code : 
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    var actionList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var &lt;span class="kwrd"&gt;value&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; Enumerable.Range(0, 10))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       actionList.Add(() =&amp;gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    }&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    actionList.ForEach(func =&amp;gt; Console.Write(&amp;quot;{0} &amp;quot;, func()));
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
Which outputs this : 
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp; 9 9 9 9 9 9 9 9 9 9
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Which is, of course, what we could have expected.
&lt;/p&gt;
&lt;p&gt;
Lambda expression have the ability to use variables that are in the scope when they are declared. This makes them very interesting, but to properly use them, it is best to understand how they are &amp;quot;materialized&amp;quot; by the compiler. 
&lt;/p&gt;
&lt;p&gt;
Like a lot of features of C#, like the &lt;a href="http://msdn.microsoft.com/en-us/library/aa664736.aspx" target="_blank" title="C# using"&gt;using&lt;/a&gt;, foreach, &lt;a href="http://msdn.microsoft.com/en-us/library/dscyy5s0.aspx" target="_blank" title="C# Iterators"&gt;iterators&lt;/a&gt; or &lt;a href="http://msdn.microsoft.com/en-us/library/c5kehkcz%28VS.80%29.aspx" target="_blank" title="C# lock"&gt;lock&lt;/a&gt;, lambdas are syntactic sugar destined to simplify the writing of code that is most of the time pretty verbose. It is possible to write the expanded code for these keyswords in C#.&lt;br /&gt;
&lt;br /&gt;
Let&amp;#39;s take this other piece of code :&lt;br /&gt;
&lt;br /&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal"&gt;&lt;/span&gt;&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp; &amp;nbsp;    &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    Action action = () =&amp;gt; Console.WriteLine(a);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    action();
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br /&gt;
The lambda expression is &amp;quot;materialized&amp;quot; by the C# compiler under the form of a &amp;quot;Display Class&amp;quot;, that allows the storage of the local variable &amp;quot;a&amp;quot; :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [CompilerGenerated]&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;sealed&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; a;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; &amp;lt;Main&amp;gt;b__0()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;          Console.WriteLine(&lt;span class="kwrd"&gt;this&lt;/span&gt;.a);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;       }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;   }
&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
We can see that the indentifiers for the generated class are not valid in C#, but are valide from the CLR point of view. We can also see that the local variable used during the declaration is present as a member variable, in the class that contains the code of the lambda expression. The compiler will then write this to create an instance of the lambda expression :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            var display = &lt;span class="kwrd"&gt;new&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass1();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            display.a = a;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            Action action = &lt;span class="kwrd"&gt;new&lt;/span&gt; Action(display.&amp;lt;Main&amp;gt;b__0);&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            action();&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br /&gt;
There also, this is not valid C#.&lt;br /&gt;
&lt;br /&gt;
But then, what happens for the foreach case so that the content of the variable is repeated ?
&lt;/p&gt;
&lt;p&gt;
If we analyze the first code sample generated by the compiler with &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank" title="Reflector"&gt;Reflector&lt;/a&gt;, there is nothing much fancy to see with the C# visualizer :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    List&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; actionList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt;();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    &lt;span class="kwrd"&gt;using&lt;/span&gt; (IEnumerator&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; CS$5$0000 = Enumerable.Range(0, 10).GetEnumerator())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        &lt;span class="kwrd"&gt;while&lt;/span&gt; (CS$5$0000.MoveNext())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = CS$5$0000.Current;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            actionList.Add(&lt;span class="kwrd"&gt;delegate&lt;/span&gt; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;            });&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;        }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;    }&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
The lambda expression is represented as an anonymous method, which is a synonym of lambda, but that does not explain the behavior.
&lt;br /&gt;
&lt;br /&gt;
We must look at the generated IL to understand the behavior, and this is the correct C# code that is generated :&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            List&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt; actionList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;&amp;gt;();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (IEnumerator&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; CS$5$0000 = Enumerable.Range(0, 10).GetEnumerator())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;               var myLambda = &lt;span class="kwrd"&gt;new&lt;/span&gt; &amp;lt;&amp;gt;c__DisplayClass4();&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;               &lt;span class="kwrd"&gt;while&lt;/span&gt; (CS$5$0000.MoveNext())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;               {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                  &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt; = CS$5$0000.Current;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; myLambda.&lt;span class="kwrd"&gt;value&lt;/span&gt; = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                  actionList.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Func&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(myLambda.b_0));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;               }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
We can easily see what the problem is : The instance of the class containing the lambda is created only once, and reused many times to assign a new value for each iteration. This explains why the execution of all the lambdas return the last enumerated value, because they all refer to the same instance of the &amp;quot;DisplayClass&amp;quot; type.
&lt;br /&gt;
&lt;br /&gt;
However, if we write the code this way :
&lt;/p&gt;
&lt;p&gt;
&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px; font-weight: normal"&gt;&lt;/span&gt;&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (var &lt;span class="kwrd"&gt;value&lt;/span&gt; &lt;span class="kwrd"&gt;in&lt;/span&gt; Enumerable.Range(0, 10))&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;int&lt;/span&gt; myValue = &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                actionList.Add(() =&amp;gt; myValue);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p&gt;
The behavior changes, and this time, each lambda has the correct value.
&lt;/p&gt;
&lt;p&gt;
From the compiler point of view, the creation of a new instance for the container class must be the consequence of the creation of a new variable. For the case of a ForEach statement, this is not the case and the variable is treated as created only once, then reused..&lt;br /&gt;
&lt;br /&gt;
So, from the compiler point of view, a ForEach loop is expanded like this :
&lt;/p&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (var it = Enumerable.Range(0, 10).GetEnumerator())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;int&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                &lt;span class="kwrd"&gt;while&lt;/span&gt; (it.MoveNext())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    &lt;span class="kwrd"&gt;value&lt;/span&gt; = it.Current;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                    actionList2.Add(() =&amp;gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;                }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;            }&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
This is probably a question of interpretation, but I wasn&amp;#39;t exactly expecting this...
&lt;/p&gt;
&lt;p&gt;
So, one must pay attention to the way local variables are used in lambda expressions, depending on their declaration location.
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ll explain in a later post why I did have to use lamda expressions in a ForEach loop.
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/pkxWvDc7mws/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/11/Lambda-Expression-and-ForEach-loops.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=cc663032-a7df-4a37-a3a6-60dc33e09385</guid>
      <pubDate>Tue, 18 Nov 2008 20:58:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=cc663032-a7df-4a37-a3a6-60dc33e09385</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=cc663032-a7df-4a37-a3a6-60dc33e09385</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/11/Lambda-Expression-and-ForEach-loops.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=cc663032-a7df-4a37-a3a6-60dc33e09385</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=cc663032-a7df-4a37-a3a6-60dc33e09385</feedburner:origLink></item>
    <item>
      <title>Working with Umbrella in .NET 3.5</title>
      <description>&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;If you&amp;#39;ve been using .NET 3.5, and the new features that are provided by C# 3.0, and especially LINQ, you must have wondered why, oh why, there isn&amp;#39;t an extension named ForEach on an IEnumerable&amp;lt;T&amp;gt;.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Well, I still haven&amp;#39;t figured that out, though it appears that it might have something to do with the fact that by nature an &lt;a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx" target="_blank" title="Action&amp;lt;T&amp;gt; Delegate - MSDN"&gt;Action&amp;lt;T&amp;gt;&lt;/a&gt; is most of the time not &amp;quot;pure&amp;quot;, which means that it modifies some states, somewhere. I can&amp;#39;t remember where I&amp;#39;ve found that explanation, though it &amp;quot;might&amp;quot; make sense from a functional point of view.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
But you may wonder why, then, is there a &lt;a href="http://msdn.microsoft.com/en-us/library/bwabdf9z.aspx" target="_blank" title="List&amp;lt;T&amp;gt;.ForEach"&gt;ForEach&lt;/a&gt; method on List&amp;lt;T&amp;gt; ? Well, I don&amp;#39;t know why there is that kind of consistency issue, but I know there is one library that somehow tries to fix this :&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="center"&gt;
&lt;font face="trebuchet ms,geneva" size="5"&gt;
&lt;a href="http://www.codeplex.com/umbrella" target="_blank" title="Umbrella on CodePlex"&gt;Umbrella&lt;/a&gt;&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;div align="center"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
This library fills the gaps left by the BCL, and adds a whole bunch of new extension methods that eases the use of .NET 3.5 classes. This library is not a framework though, mainly because you don&amp;#39;t need to redesign your whole application to use it.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
A few weeks ago during a presentation of Umbrella at the &lt;a href="http://www.dotnetmontreal.com/" target="_blank" title=".NET Montreal User Group"&gt;.NET User Group of Montreal&lt;/a&gt;, the creators Francois Tanguay and Erik Renaud from &lt;a href="http://www.nventive.net/dnn/" target="_blank" title="nVentive"&gt;nVentive&lt;/a&gt;, were asked the question &lt;em&gt;&amp;quot;Where do we start ?&amp;quot;&lt;/em&gt;. This is a tough question to answer, because of the nature of umbrella, which &amp;quot;plugs&amp;quot; itself everywhere it can.&lt;/font&gt;
&lt;/div&gt;
&lt;h1&gt;Using Umbrella&lt;/h1&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;Let&amp;rsquo;s see a simple example:&lt;/font&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Enumerable&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Range(20, 30)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .ForEach(&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (index, &lt;span class="kwrd"&gt;value&lt;/span&gt;) =&amp;gt; &amp;quot;Value #{0}={1}&amp;quot;.InvariantCultureFormat(index, &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; );
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;As you can see, using Umbrella requires most of the time the use of &lt;a href="http://jaylee.org/admin/Pages/lambda%20expressions" target="_blank" title="Lambda Expressions"&gt;lambda expressions&lt;/a&gt;. Here, this example is an answer to the question &amp;quot;&lt;em&gt;How can I get the index of the enumerated value in a foreach statement ?&amp;quot;&lt;/em&gt;.&lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Another extension provided by Umbrella is the Remove method on an ICollection by specifying a predicated to select elements to be removed. &lt;/font&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var values = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;(Enumerable.Range(1, 10));&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; values.Remove(v =&amp;gt; v &amp;gt; 4);
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;p align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;Sure, you can write some code that does this, but you&amp;#39;ll have to create a temporary list to store elements to be removed, then remove them from the collection.&lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;There is also an extension on IDictionary&amp;lt;&amp;gt; that simplifies the use of TryGetValue which requires an &amp;ldquo;out&amp;rdquo; argument, which is particularly annoying to write. Umbrella provides a TryGetValueOrDefault that either gives you the value for the key you requested, or default(TValue) if the key is not found.&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&amp;nbsp;
&lt;/div&gt;
&lt;h2&gt;
The Action.ToDisposable() extension method &lt;/h2&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;One particularly interesting extension is the ability to encapsulate an Action delegate into an anonymous disposable instance. Let&amp;rsquo;s say that we need to profile the duration of a particular scope of code. We would need to write something like this :&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; var w = Stopwatch.StartNew();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 1000; i++)&amp;nbsp; { }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(w.Elapsed);
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;We would have to write the enclosing code to time for each portion of code we would need to profile. You could of course write a class that would do this on purpose :&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;class&lt;/span&gt; ProfileScope : IDisposable&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Stopwatch w = Stopwatch.StartNew();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;void&lt;/span&gt; IDisposable.Dispose()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(w.Elapsed);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; &lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;And it&amp;rsquo;s being used like with a &amp;ldquo;using&amp;rdquo; statement :&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;br /&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;using&lt;/span&gt; (&lt;span class="kwrd"&gt;new&lt;/span&gt; ProfileScope())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; 1000; i++)&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; 
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;This time, timing a block of code is somehow easier to write, however, there is a way to simplify the writing of the writing of the utility class by doing this:&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;static&lt;/span&gt; IDisposable CreateProfileScope()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var w = Stopwatch.StartNew();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;return&lt;/span&gt; Actions.Create(() =&amp;gt; Console.WriteLine(w.Elapsed)).ToDisposable();&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;We can use here the ToDisposable extension to be able to call the specified action in the dispose method of some disposable class.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
The point of this code is to avoid exposing the inner details of the profiling code, and just expose a known and generic way for executing something at the end of a scope.&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;h2&gt;Extension Points&lt;br /&gt;
&lt;/h2&gt;
&lt;div align="justify"&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;There is one drawback when using extension methods: They tend to &amp;ldquo;pollute&amp;rdquo; the original type. By pollute I mean that they appear in the IntelliSense window. Because it is easy to add extension methods, you end up having hundreds of new methods on a type, which make IntelliSense much less useable.&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
The Umbrella guys came up with the idea of Extension Points, which are a way to group extension methods the namespaces do for types.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
This is somehow a hack from a code perspective, but is rather ingenious from a usability perspective. For instance, extending the serialization applies to every type that exists, and placing all serialization extension methods directly on System.Object is not a good idea.&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
&lt;/font&gt;&lt;br /&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Extensions points are used like this:&lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;&lt;/font&gt;&lt;br /&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;div class="code"&gt;

&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;using&lt;/span&gt; (MemoryStream stream = &lt;span class="kwrd"&gt;new&lt;/span&gt; MemoryStream())&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="kwrd"&gt;int&lt;/span&gt; a = 0;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.Serialization().Binary(stream);&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span class="rem"&gt;// ...&lt;br /&gt;&lt;/span&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p&gt;
&lt;/div&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;font size="2"&gt;Serialization is an extension method placed on every object that returns an SerializationExtensionPoint instance, and the &amp;ldquo;Binary&amp;rdquo; method extends that type instead of System.Object.&lt;/font&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;p align="justify"&gt;
&lt;font size="2"&gt;It is important to remember that Umbrella is for most of its code is not &amp;quot;rocket science&amp;quot;, as it probably contains code that you may already have partially developed for your own project. It&amp;#39;s only the amount of small but useful utility methods that Umbrella provides that makes it worth using. &lt;/font&gt;
&lt;/p&gt;
&lt;div align="justify"&gt;
&lt;/div&gt;
&lt;div align="justify"&gt;
&lt;font size="2"&gt;
I&amp;rsquo;ll be writing a few other posts about Umbrella; there are a lot of extensions in there that are great time savers.&lt;/font&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/2obaXBwxXLo/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/11/Working-with-Umbrella-in-NET-3-5.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=cdd0f59c-3e32-4da6-9e40-463554913a86</guid>
      <pubDate>Sat, 08 Nov 2008 16:06:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=cdd0f59c-3e32-4da6-9e40-463554913a86</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=cdd0f59c-3e32-4da6-9e40-463554913a86</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/11/Working-with-Umbrella-in-NET-3-5.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=cdd0f59c-3e32-4da6-9e40-463554913a86</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=cdd0f59c-3e32-4da6-9e40-463554913a86</feedburner:origLink></item>
    <item>
      <title>Speaker Idol Montreal</title>
      <description>&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;Yesterday, Monday 3rd, was the day of Speaker Idol Montreal.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;I&amp;#39;d
like to thank every attendee for being here and listening all of these
great presentations ! Ten minutes is a format that&amp;#39;s a bit rough
though, one&amp;#39;s got to learn every word to be said to make a good point
during that kind of presentation length. (And don&amp;#39;t rely on the computer
that&amp;#39;s available there... You might end up not being able to use the
keyboard :) )&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;Anyway, if you were interested by the subject of my
presentation, you may find a more thorough explanation on this blog
post about &lt;a href="http://jaylee.org/post/2007/02/WPF-DataContext-and-CurrentItem.aspx" target="_blank"&gt;DataBinding in WPF&lt;/a&gt;. By the way, you may also be interested in this post about &lt;a href="http://jaylee.org/post/2007/02/WPF-DataBinding-and-Application-Settings.aspx" target="_blank"&gt;DataBinding Application Settings&lt;/a&gt;. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;See you next time in the .NET Montreal User Group !&lt;/font&gt;
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/4GAZeGUIIhk/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/11/Speaker-Idol-Montreal.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=031fa4aa-bf0d-4345-87f2-e0bf7a26290e</guid>
      <pubDate>Tue, 04 Nov 2008 06:56:00 -0700</pubDate>
      <category>.NET</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=031fa4aa-bf0d-4345-87f2-e0bf7a26290e</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=031fa4aa-bf0d-4345-87f2-e0bf7a26290e</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/11/Speaker-Idol-Montreal.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=031fa4aa-bf0d-4345-87f2-e0bf7a26290e</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=031fa4aa-bf0d-4345-87f2-e0bf7a26290e</feedburner:origLink></item>
    <item>
      <title>Montréal Bus Stop Locator Site and the iPhone</title>
      <description>&lt;p&gt;
&lt;em&gt;Cet article est disponible en francais &lt;a href="http://blogs.codes-sources.com/jay/archive/2008/11/01/les-arrets-de-bus-de-montreal-sur-iphone.aspx"&gt;ici&lt;/a&gt;.&lt;/em&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;I&amp;#39;ve updated my utility WebSite to look a bit better on the iPhone (Thanks, Mr Sanx). 
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Now, the next &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;buses &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;schedule are a bit easier to read and past schedules are visually easier to leave out.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;There are some other features that are in the oven, I hope to push them online soon enough :) &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;The geolocation on the iPhone would be a plus, but unfortunately, Google Gears is not available on the iPhone. There seem to be some sort of extension named weblocate:// to do this from a web application, but that seems a bit shady...&lt;/font&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;Anyway, you can visit the Web Site here from your &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;Windows Mobile, &lt;/font&gt;&lt;font face="trebuchet ms,geneva" size="2"&gt;iPhone, or desktop computer at this address :&lt;br /&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt;
	&lt;font face="trebuchet ms,geneva" size="4"&gt;&lt;a href="http://jaylee.org/stm"&gt;http://jaylee.org/stm&lt;/a&gt;&lt;/font&gt;
&lt;/blockquote&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;font face="trebuchet ms,geneva" size="2"&gt;
Here&amp;#39;s an example of what it&amp;#39;s looking now :&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;img src="http://jaylee.org/image.axd?picture=stm-stoplist-english.png" alt="" /&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;img src="http://jaylee.org/image.axd?picture=stm-stopinfo-english.png" alt="" /&gt;
&lt;/p&gt;
</description>
      <link>http://feedproxy.google.com/~r/JeromeLabanBlog/~3/bbgVF9z4F8Y/post.aspx</link>
      <author>Jay</author>
      <comments>http://jaylee.org/post/2008/11/Montreal-Bus-Stop-Locator-Site-and-the-iPhone.aspx#comment</comments>
      <guid isPermaLink="false">http://jaylee.org/post.aspx?id=83a9ce4f-1c23-4f54-8ecc-f1a6e70b9b1c</guid>
      <pubDate>Sat, 01 Nov 2008 11:13:00 -0700</pubDate>
      <category>Bus Stop Locator</category>
      <dc:publisher>Jay</dc:publisher>
      <pingback:server>http://jaylee.org/pingback.axd</pingback:server>
      <pingback:target>http://jaylee.org/post.aspx?id=83a9ce4f-1c23-4f54-8ecc-f1a6e70b9b1c</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://jaylee.org/trackback.axd?id=83a9ce4f-1c23-4f54-8ecc-f1a6e70b9b1c</trackback:ping>
      <wfw:comment>http://jaylee.org/post/2008/11/Montreal-Bus-Stop-Locator-Site-and-the-iPhone.aspx#comment</wfw:comment>
      <wfw:commentRss>http://jaylee.org/syndication.axd?post=83a9ce4f-1c23-4f54-8ecc-f1a6e70b9b1c</wfw:commentRss>
    <feedburner:origLink>http://jaylee.org/post.aspx?id=83a9ce4f-1c23-4f54-8ecc-f1a6e70b9b1c</feedburner:origLink></item>
  </channel>
</rss>
