<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>The Inquisitive Coder - Davy Brion&#039;s Blog &#187; .NET bugs</title> <atom:link href="http://davybrion.com/blog/category/net-bugs/feed/" rel="self" type="application/rss+xml" /><link>http://davybrion.com/blog</link> <description>inquisitive: adjective. given to inquiry, research, or asking questions; eager for knowledge; intellectually curious</description> <lastBuildDate>Mon, 14 May 2012 21:08:36 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>More On System.Tuple And Serialization/Deserialization</title><link>http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/</link> <comments>http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/#comments</comments> <pubDate>Wed, 23 Jun 2010 19:19:07 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category><guid
isPermaLink="false">http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/</guid> <description><![CDATA[As i mentioned in my last post, i ran into a serialization problem with a Tuple reference when returning it from a WCF call.&#160; It failed with the typical exception you get when a type can not be deserialized. Unfortunately, the message of the exception that i got is the same as it is when [...]]]></description> <content:encoded><![CDATA[<p>As i mentioned in my <a
href="http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/" target="_blank">last post</a>, i ran into a serialization problem with a Tuple reference when returning it from a WCF call.&#160; It failed with the typical exception you get when a type can not be deserialized. Unfortunately, the message of the exception that i got is the same as it is when a type can not be serialized, though both situations are actually quite different.&#160; One of my readers left a comment saying that he didn’t have problems serializing/deserializing a Tuple (by the way: am i the only one who has major problems with typing the word ‘tuple’? whenever i wanna use it, i always end up with ‘type’ before i realize my mistake) through WCF.&#160;</p><p>So why did it work for him, yet failed in my situation? The answer turns out to be quite simple.&#160; If you look at the Tuple type of .NET 4 in Reflector, you’ll see this:</p><p><a
href="http://davybrion.com/pictures/Mor.TupleAndSerializationDeserialization_124CB/tuple_dotnet.png" rel="prettyPhoto[2356]"><img
style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="tuple_dotnet" border="0" alt="tuple_dotnet" src="http://davybrion.com/pictures/Mor.TupleAndSerializationDeserialization_124CB/tuple_dotnet_thumb.png" width="493" height="40" /></a></p><p>So it actually is serializable.&#160; The thing is, my client is not a .NET project, it’s Silverlight.&#160; And the Tuple type in Silverlight looks like this:</p><p><a
href="http://davybrion.com/pictures/Mor.TupleAndSerializationDeserialization_124CB/tuple_silverlight.png" rel="prettyPhoto[2356]"><img
style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="tuple_silverlight" border="0" alt="tuple_silverlight" src="http://davybrion.com/pictures/Mor.TupleAndSerializationDeserialization_124CB/tuple_silverlight_thumb.png" width="497" height="33" /></a></p><p></p><p>Silverlight still doesn’t support the Serializable attribute and the Tuple types don’t have a parameterless constructor, so that’s why it can’t deserialize a Tuple instance when it’s returned from a WCF call.&#160; I can’t believe i didn’t think of this earlier since i’ve been bitten by this problem a few more times (not with the Tuple type, but with other Serializable classes) in the past, but then again, i can’t believe something like this still doesn’t work when using .NET <strong>4</strong>, Silverlight <strong>4</strong> and WCF<strong> 4 </strong>together.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F06%2Fmore-on-system-tuple-and-serializationdeserialization%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/"  data-text="More On System.Tuple And Serialization/Deserialization" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/06/more-on-system-tuple-and-serializationdeserialization/feed/</wfw:commentRss> <slash:comments>3</slash:comments> </item> <item><title>My First Request For The Next .NET Version</title><link>http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/</link> <comments>http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/#comments</comments> <pubDate>Wed, 23 Jun 2010 11:38:37 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category><guid
isPermaLink="false">http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/</guid> <description><![CDATA[Please, pretty please, make the Tuple class serializable… i just got this exception: Type 'System.Tuple`2[System.Guid,System.Nullable`1[System.Guid]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public [...]]]></description> <content:encoded><![CDATA[<p>Please, pretty please, make the Tuple class serializable… i just got this exception:</p><p>Type 'System.Tuple`2[System.Guid,System.Nullable`1[System.Guid]]' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public <strong>and has a parameterless constructor</strong> - all public members of the type will then be serialized, and no attributes will be required.</p><p>That’s all… now if you’ll excuse me, i gotta go include a useless DTO in my project.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F06%2Fmy-first-request-for-the-next-net-version%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/"  data-text="My First Request For The Next .NET Version" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/06/my-first-request-for-the-next-net-version/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>MSDTC Woes With NServiceBus And NHibernate</title><link>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/</link> <comments>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/#comments</comments> <pubDate>Fri, 19 Mar 2010 10:52:16 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category> <category><![CDATA[MSDTC]]></category> <category><![CDATA[NHibernate]]></category> <category><![CDATA[nservicebus]]></category><guid
isPermaLink="false">http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/</guid> <description><![CDATA[I’ve spent about 3 days trying to get something working that should’ve just worked.&#160; I basically wanted some .NET code to use a distributed transaction to update some data in a database, and then publish a message on the service bus.&#160; I want to do this in a distributed transaction because if something goes wrong, [...]]]></description> <content:encoded><![CDATA[<p>I’ve spent about 3 days trying to get something working that should’ve just worked.&#160; I basically wanted some .NET code to use a distributed transaction to update some data in a database, and then publish a message on the service bus.&#160; I want to do this in a distributed transaction because if something goes wrong, i want to roll back both transactions (the database change and the published message).&#160; Normally, this should just work if you have MS DTC configured correctly.&#160; On my machine, i enabled Network DTC Access, and allowed outbound transaction communication.&#160; On the database server, Network DTC Access was already enabled and both outbound and inbound communication was allowed.&#160;</p><p>Now the thing is, i’d either expect DTC to fail outright or to just work.&#160; But it shouldn’t fail in one situation, and work in another.&#160; On my machine, it failed in the following situation (which i’ll further refer to as Situation A):</p><ol><li>open a transaction scope</li><li>open an nhibernate session</li><li>hit the db</li><li>publish a message through nservicebus</li><li>close the nhibernate session</li><li>complete and close the transaction scope</li></ol><p>Step 4 and 5 could be switched around but it didn’t make a difference.&#160; In Situation A, i always got a TransactionManagerCommunicationException with the following message:</p><blockquote><p>Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool.</p></blockquote><p>Everyone who’s worked with MSDTC before probably knows that exception since it usually takes some fiddling with the settings to make things work.&#160; The thing is, i was pretty sure that my settings, as well as the ones on the database server were correct.&#160; Unfortunately, DTCPing didn’t confirm that since that too failed.</p><p>However, i also tried the following sequence of events (Situation B):</p><ol><li>open a transaction scope</li><li>open an nhibernate session</li><li>publish a message</li><li>hit the db</li><li>close the nhibernate session</li><li>complete and close the transaction scope</li></ol><p>And guess what.&#160; That actually worked.&#160; With full DTC transaction semantics.&#160; The DTC statistics on the server confirmed that it was indeed using a DTC transaction, and if i made the code fail with an exception both the database action and the published message were correctly rolled back.</p><p>So the question is: why on earth does it only work when i publish a message before i hit the db?</p><p>During my investigation i noticed that in Situation A, the internal transaction that the transaction scope was using was a SqlDelegatedTransaction.&#160; Which, if i’m not mistaken is an LTM transaction.&#160; When trying to send a message to a message queue, the transaction manager tries to promote the current transaction to an OletxCommittableTransaction since the OleTx transaction protocol is required when using MSMQ (it doesn’t support LTM transactions).&#160; For some reason, promoting the SqlDelegatedTransaction to a full DTC (OleTx) transaction fails on my machine.</p><p>In Situation B, the internal transaction is promoted to an OletxCommittableTransaction as soon as you try to send the message to a message queue.&#160; Once it’s time to hit the DB, NHibernate nicely works together with the OletxCommittableTransaction and everything just works.</p><p>Now, i have no idea on earth why promotion of a SqlDelegatedTransaction fails, but after a long number of attempts and experiments to get it working correctly, i sorta gave up and figured i’d have to resort to a hack.&#160; What i basically needed was for the transaction scope’s internal transaction to automatically be promoted to an OletxCommittableTransaction <em>before<strong> </strong></em>i’d hit the database and without having to publish a dummy message at the beginning of the transaction.</p><p>I found one way of doing this which, while being a huge hack, is still relatively clean i think.&#160; I wrote the following class:</p><div
style="font-family: consolas; background: white; color: black; font-size: 10pt"><p
style="margin: 0px">&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">class</span> <span
style="color: #2b91af">DummyEnlistmentNotification</span> : <span
style="color: #2b91af">IEnlistmentNotification</span></p><p
style="margin: 0px">&#160;&#160;&#160; {</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">static</span> <span
style="color: blue">readonly</span> <span
style="color: #2b91af">Guid</span> Id = <span
style="color: blue">new</span> <span
style="color: #2b91af">Guid</span>(<span
style="color: #a31515">&quot;E2D35055-4187-4ff5-82A1-F1F161A008D0&quot;</span>);</p><p
style="margin: 0px">&#160;</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">void</span> Prepare(<span
style="color: #2b91af">PreparingEnlistment</span> preparingEnlistment)</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; preparingEnlistment.Prepared();</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p
style="margin: 0px">&#160;</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">void</span> Commit(<span
style="color: #2b91af">Enlistment</span> enlistment)</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p
style="margin: 0px">&#160;</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">void</span> Rollback(<span
style="color: #2b91af">Enlistment</span> enlistment)</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p
style="margin: 0px">&#160;</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span
style="color: blue">public</span> <span
style="color: blue">void</span> InDoubt(<span
style="color: #2b91af">Enlistment</span> enlistment)</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; enlistment.Done();</p><p
style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p
style="margin: 0px">&#160;&#160;&#160; }</p></div><p>&#160;</p><p>Then, right after opening the transaction scope and before doing anything else, i do this:</p><div
style="font-family: consolas; background: white; color: black; font-size: 10pt"><p
style="margin: 0px">&#160;&#160;&#160; <span
style="color: #2b91af">Transaction</span>.Current.EnlistDurable(<span
style="color: #2b91af">DummyEnlistmentNotification</span>.Id, <span
style="color: blue">new</span> <span
style="color: #2b91af">DummyEnlistmentNotification</span>(), <span
style="color: #2b91af">EnlistmentOptions</span>.None);</p></div><p>&#160;</p><p>This basically tells the System.Transactions infrastructure that we’re adding our own Resource Manager to the current transaction.&#160; And because it’s a durable Resource Manager, it now automatically promotes the internal transaction to an OletxCommittableTransaction and everything just works.&#160; While our Resource Manager participates in the 2-phase-commit process, it doesn’t actually do anything.&#160; It’s sole purpose is to force the creation of an OletxCommittableTransaction.</p><p>Like i said, it’s a hack but it’s still relatively clean.&#160; I still have no idea why i needed to resort to this hack though… If anyone can shed some light on this, i’d highly appreciate it <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Also, if you ever want to learn more about transactions in .NET or distributed transactions in particular, you really need to check out <a
href="http://www.codeproject.com/KB/WCF/NETTx.aspx" target="_blank">this article</a>.&#160; Without it, i probably wouldn’t have figured out what to do <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2010%2F03%2Fmsdtc-woes-with-nservicebus-and-nhibernate%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/"  data-text="MSDTC Woes With NServiceBus And NHibernate" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2010/03/msdtc-woes-with-nservicebus-and-nhibernate/feed/</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>The Joys Of Debugging ASP.NET Memory Leaks</title><link>http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/</link> <comments>http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/#comments</comments> <pubDate>Mon, 06 Apr 2009 20:37:14 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category> <category><![CDATA[ASP.NET]]></category> <category><![CDATA[Memory Management]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=1271</guid> <description><![CDATA[One of my coworkers describes a very interesting memory leak he just fixed. Be sure to read his post to get the entire story. We basically had a custom UserControl which contained (among other things) a Repeater which would render another custom UserControl. Nothing really weird there, right? The problem was that the custom UserControl [...]]]></description> <content:encoded><![CDATA[<p>One of my coworkers <a
href="http://blog.kristofrennen.be/index.php/2009/04/how-an-aspnet-databind-can-cause-a-memory-leak/">describes</a> a very interesting memory leak he just fixed.  Be sure to read his post to get the entire story.</p><p>We basically had a custom UserControl which contained (among other things) a Repeater which would render another custom UserControl.  Nothing really weird there, right?  The problem was that the custom UserControl that was created by the Repeater explicitly needed to be disposed.  No problem, System.Web.UI.Control implements IDisposable so we could just override the Dispose method, perform our cleanup there and then proceed with the base Dispose implementation.</p><p>Now, i'm far from an ASP.NET expert but i was under the impression that all Page and UserControl instances would always have their Dispose method called if they were created by other ASP.NET controls (containing pages or controls).  After all, what's the point in implementing IDisposable in the base Control class if you're not even going to guarantee proper usage of the pattern, right?</p><p>Well, as Kristof describes in his post, there is <a
href="http://blog.kristofrennen.be/index.php/2009/04/how-an-aspnet-databind-can-cause-a-memory-leak/">at least one situation</a> where a UserControl is not disposed of, even though it was created by a Repeater.  In our case, the leak was subtle.  It took a stress test of 10 hours with a load that would be comparable to real world usage of one month to expose the leak.  A lot of people would say "oh, let's just recycle the application pool periodically and everything is A-OK".  But the very idea of having to recycle an application pool periodically to keep a system up and running is just a cop out to me.  Good code should not require periodic restarts.  Period.</p><p>I wonder how many ASP.NET WebForms applications might actually have the same (or at least similar) problem(s) like the one Kristof encountered.   If everyone keeps recycling their application pools periodically, we unfortunately may never found out.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2009%2F04%2Fthe-joys-of-debugging-aspnet-memory-leaks%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/"  data-text="The Joys Of Debugging ASP.NET Memory Leaks" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2009/04/the-joys-of-debugging-aspnet-memory-leaks/feed/</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Exceptional Exception Handling Behavior</title><link>http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/</link> <comments>http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/#comments</comments> <pubDate>Wed, 08 Oct 2008 16:48:59 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category><guid
isPermaLink="false">http://davybrion.com/blog/?p=501</guid> <description><![CDATA[We ran into a weird issue at work today. Take a look at the following code: &#160;&#160;&#160; public class MyException : Exception { } &#160; &#160;&#160;&#160; [TestFixture] &#160;&#160;&#160; public class TestFixture &#160;&#160;&#160; { &#160;&#160;&#160; &#160;&#160;&#160; [Test] &#160;&#160;&#160; &#160;&#160;&#160; public void Test() &#160;&#160;&#160; &#160;&#160;&#160; { &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; var exception = GetThrownException&#60;MyException&#62;(() =&#62; { throw new [...]]]></description> <content:encoded><![CDATA[<p>We ran into a weird issue at work today.  Take a look at the following code:</p><p><code></p><div
style="font-family: Consolas; font-size: 10pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">MyException</span> : <span
style="color: #2b91af;">Exception</span> { }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; [<span
style="color: #2b91af;">TestFixture</span>]</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">TestFixture</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [<span
style="color: #2b91af;">Test</span>]</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">void</span> Test()</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> exception = GetThrownException&lt;<span
style="color: #2b91af;">MyException</span>&gt;(() =&gt; { <span
style="color: blue;">throw</span> <span
style="color: blue;">new</span> <span
style="color: #2b91af;">MyException</span>(); });</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: #2b91af;">Assert</span>.IsNotNull(exception);</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> T GetThrownException&lt;T&gt;(<span
style="color: #2b91af;">Action</span> action)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">where</span> T : <span
style="color: #2b91af;">Exception</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">try</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; action();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">catch</span> (T exception)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> exception;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> <span
style="color: blue;">null</span>;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>If you simply run that test, without debugging, it works (both with Testdriven.NET and Resharper). If you run it with a debugger, it fails with the following message:</p><p>ExceptionWeirdness.MyException: Exception of type 'ExceptionWeirdness.MyException' was thrown.</p><p>Pretty weird huh?</p><p>Let's change the code of the GetThrownException method to this:</p><p><code></p><div
style="font-family: Consolas; font-size: 10pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> T GetThrownException&lt;T&gt;(<span
style="color: #2b91af;">Action</span> action)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">where</span> T : <span
style="color: #2b91af;">Exception</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">try</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; action();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">catch</span> (T exception)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> exception;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">catch</span> (<span
style="color: #2b91af;">Exception</span> e)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> (T)e;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> <span
style="color: blue;">null</span>;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>Now the test works all the time, even with the debugger attached.</p><p>Weird huh? At first i wondered if it was somehow NUnit related... but then i tried running this program:</p><p><code></p><div
style="font-family: Consolas; font-size: 10pt; color: black; background: white;"><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">public</span> <span
style="color: blue;">class</span> <span
style="color: #2b91af;">MyException</span> : <span
style="color: #2b91af;">Exception</span> { }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; <span
style="color: blue;">class</span> <span
style="color: #2b91af;">Program</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">static</span> <span
style="color: blue;">void</span> Main(<span
style="color: blue;">string</span>[] args)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">var</span> exception = GetThrownException&lt;<span
style="color: #2b91af;">MyException</span>&gt;(() =&gt; { <span
style="color: blue;">throw</span> <span
style="color: blue;">new</span> <span
style="color: #2b91af;">MyException</span>(); });</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">private</span> <span
style="color: blue;">static</span> T GetThrownException&lt;T&gt;(<span
style="color: #2b91af;">Action</span> action)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">where</span> T : <span
style="color: #2b91af;">Exception</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">try</span></p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; action();</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">catch</span> (T exception)</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> exception;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span
style="color: blue;">return</span> <span
style="color: blue;">null</span>;</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p><p
style="margin: 0px;">&nbsp;&nbsp;&nbsp; }</p></div><p></code></p><p>Run it without the debugger, and it works.  Run it with the debugger and it fails.</p><p>This is using .NET 3.5 SP1.</p><p>I don't understand why it behaves like this... it should work all the time right? I am overdue for my weekly brain-fart so i might be missing something really stupid though.</p><p>Either way, the first person to explain this behavior gets awarded with the "Davy Brion's Hero Of The Week" title <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Oh, and this was in a clean solution... so there's no duplicate MyException types or anything like that.</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F10%2Fexceptional-exception-handlingbehavior%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/"  data-text="Exceptional Exception Handling Behavior" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2008/10/exceptional-exception-handlingbehavior/feed/</wfw:commentRss> <slash:comments>20</slash:comments> </item> <item><title>XDocument&#8217;s WriteTo method gotcha</title><link>http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/</link> <comments>http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/#comments</comments> <pubDate>Fri, 25 Apr 2008 15:12:47 +0000</pubDate> <dc:creator>Davy Brion</dc:creator> <category><![CDATA[.NET bugs]]></category><guid
isPermaLink="false">http://ralinx.wordpress.com/?p=93</guid> <description><![CDATA[Suppose you have an xml document in memory using an XDocument instance. Then you need to write the contents of the xml document to an XmlWriter... no worries, the XDocument class provides the WriteTo method which takes an XmlWriter as a parameter. The contents of the xml document are then nicely written to the XmlWriter. [...]]]></description> <content:encoded><![CDATA[<p>Suppose you have an xml document in memory using an XDocument instance. Then you need to write the contents of the xml document to an XmlWriter... no worries, the XDocument class provides the WriteTo method which takes an XmlWriter as a parameter. The contents of the xml document are then nicely written to the XmlWriter.</p><p>Unless... you're using an XmlWriter which was created with an XmlWriterSettings instance with OutputMethod set to XmlOutputMethod.Text and your xml document is larger than 6144 bytes! The writer will only write the first 6144 bytes and after that, it just stops.  No exception, no nothing. The method returns as if everything was OK. But the underlying stream your XmlWriter wrote to contains faulty data. A very nice way to spend a friday afternoon <img
src='http://d18sni7re4ly7f.cloudfront.net/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p>In case you're wondering why: The XmlWriter's static Create method creates an instance of XmlUtf8RawTextWriter when OutputMethod is set to XmlOutputMethod.Text. This specific Writer has an internal buffer which is initialized in its constructor to be 6144 bytes long.  Apparantly, it doesn't think it's worth throwing an exception if you try to write too much data...</p><div
class="bottomcontainerBox" style=""><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <iframe
src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fdavybrion.com%2Fblog%2F2008%2F04%2Fxdocuments-writeto-method-gotcha%2F&amp;layout=button_count&amp;show_faces=false&amp;width=85&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:85px; height:21px;"></iframe></div><div
style="float:left; width:80px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <g:plusone size="medium" href="http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/"></g:plusone></div><div
style="float:left; width:95px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"> <a
href="http://twitter.com/share" class="twitter-share-button" data-url="http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/"  data-text="XDocument&#8217;s WriteTo method gotcha" data-count="horizontal" data-via="davybrion"></a></div><div
style="float:left; width:105px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script type="in/share" data-url="http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/" data-counter="right"></script></div><div
style="float:left; width:85px;padding-right:10px; margin:4px 4px 4px 4px;height:30px;"><script src="http://www.stumbleupon.com/hostedbadge.php?s=1&amp;r=http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/"></script></div></div><div
style="clear:both"></div><div
style="padding-bottom:4px;"></div>]]></content:encoded> <wfw:commentRss>http://davybrion.com/blog/2008/04/xdocuments-writeto-method-gotcha/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 2/33 queries in 0.018 seconds using disk: basic
Object Caching 691/754 objects using disk: basic
Content Delivery Network via Amazon Web Services: CloudFront: d18sni7re4ly7f.cloudfront.net

Served from: davybrion.com @ 2012-05-23 14:05:54 -->
