<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5389857</id><updated>2011-09-06T04:55:41.928-03:00</updated><title type='text'>Daniel Turini's Lair</title><subtitle type='html'>.NET, software development in Brazil and general amusements.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>45</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5389857.post-113343979910557545</id><published>2005-12-01T10:23:00.000-02:00</published><updated>2005-12-01T10:23:19.153-02:00</updated><title type='text'>Firefox 1.5 does not install</title><content type='html'>Sigh... Does everybody has problems like me with software? I stumble across, say, 10 or 20 software bugs each day.&lt;br /&gt;Now, it was the new Firefox installation. It simply didn't start. It fails silently, and so fast that it doesn't even appear on task manager.&lt;br /&gt;Reinstalling the old Firefox 1.0.7 brought it back to life, but I wanted the new Firefox so badly (although I don't know why :) )&lt;br /&gt;Finally, I found a good soul, &lt;a href="https://bugzilla.mozilla.org/show_bug.cgi?id=308374#c9"&gt;James Ross&lt;/a&gt;, that managed to solve the problem:&lt;br /&gt;&lt;quote&gt;&lt;br /&gt;To fix any build in this situation, do this:&lt;br /&gt;  1. Make sure you're logged in with full permissions on the install folder.&lt;br /&gt;  2. Delete all components\*.xpt files EXCEPT browser.xpt.&lt;br /&gt;  3. Delete compreg.dat.&lt;br /&gt;  4. Make sure .autoreg exists in the firefox.exe folder.&lt;br /&gt;  5. Start Firefox.&lt;br /&gt;&lt;br /&gt;Now, the problem is relatively simple - the components directory has the&lt;br /&gt;contents of a non-static Firefox build [1] in it. I don't know for sure if&lt;br /&gt;mozilla.org ever released such a build, but I'm willing to bet most other&lt;br /&gt;builds are non-static (all builds were this by default until very recently).&lt;br /&gt;&lt;br /&gt;Interestingly, though, all the XPTs are dated 9th Nov 2004, which *is* when&lt;br /&gt;Firefox 1.0 was originally released.&lt;br /&gt;&lt;br /&gt;So, I have a question for everyone with this problem: did you ever install a&lt;br /&gt;version that was not an official mozilla.org release?&lt;br /&gt;&lt;br /&gt;[1] In a static build, all the XPT files are bunched in to one (browser.xpt),&lt;br /&gt;rather than having lots of little ones with different names.&lt;br /&gt;&lt;/quote&gt;&lt;br /&gt;&lt;br /&gt;Answering his question, I installed MOOX optimized builds in the past. It seems that MOOX managed to corrupt something.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-113343979910557545?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/113343979910557545/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=113343979910557545' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/113343979910557545'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/113343979910557545'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/12/firefox-15-does-not-install.html' title='Firefox 1.5 does not install'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-112170907126578202</id><published>2005-07-18T14:51:00.000-03:00</published><updated>2005-07-18T14:51:11.293-03:00</updated><title type='text'>SELECT MAX(NULL) FROM DUAL;</title><content type='html'>Never do that.&lt;br /&gt;Actually, never &lt;i&gt;SELECT MAX(col) FROM tab&lt;/i&gt; where col is a NULLable column on an Oracle client. Oh, and don't forget that an empty string is a NULL on Oracle.&lt;br /&gt;It seems that the .NET framework has a bug, and, when you do this, you'll get a NullReferenceException from the .NET Oracle provider.&lt;br /&gt;Weird.&lt;br /&gt;Time to review all my SELECT MAX, SELECT MIN and convert from:&lt;br /&gt;SELECT MAX(col) FROM tab&lt;br /&gt;to&lt;br /&gt;SELECT MAX(col) FROM tab WHERE col IS NOT NULL&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-112170907126578202?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/112170907126578202/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=112170907126578202' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112170907126578202'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112170907126578202'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/07/select-maxnull-from-dual.html' title='SELECT MAX(NULL) FROM DUAL;'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-112109567417408049</id><published>2005-07-11T12:27:00.000-03:00</published><updated>2005-07-11T12:27:54.226-03:00</updated><title type='text'>I just keep running on weird errors</title><content type='html'>&lt;i&gt;The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/MyWebApplication1'. 'HTTP/1.1 500 Internal Server Error'.&lt;/i&gt;&lt;br /&gt;Two hours later: we had an internal change on our network a few weeks ago, and the user/password on the processModel tag on MACHINE.CONFIG file was wrong. As you can see, I wasn't using ASP.NET so much...&lt;br /&gt;I'm yet to see an IDE that gives less information than VS.NET when connecting to IIS...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-112109567417408049?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/112109567417408049/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=112109567417408049' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112109567417408049'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112109567417408049'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/07/i-just-keep-running-on-weird-errors.html' title='I just keep running on weird errors'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-112006759147310809</id><published>2005-06-29T14:53:00.000-03:00</published><updated>2005-06-29T14:53:11.500-03:00</updated><title type='text'>I love Portland Patterns Repository</title><content type='html'>It seems that my idea of Firefighting simulations were already invented. There are two patterns on the PPR, one is &lt;a href="http://c2.com/cgi-bin/wiki?DefectSeeding"&gt;Defect Seeding&lt;/a&gt; and the other is &lt;a href="http://c2.com/cgi-bin/wiki?MutationTesting"&gt;Mutation Testing&lt;/a&gt;. It seems that my firefighting simulation is exactly the Defect Seeding pattern and Mutation Testing is a technique for automatically changing programs and finding unit test failures.&lt;br /&gt;Well, maybe some day I invent something that was not already invented. But I still think it may be useful here, and probably we'll start using it.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-112006759147310809?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/112006759147310809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=112006759147310809' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112006759147310809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/112006759147310809'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/06/i-love-portland-patterns-repository.html' title='I love Portland Patterns Repository'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-111990309040986219</id><published>2005-06-27T17:11:00.000-03:00</published><updated>2005-06-27T17:36:31.546-03:00</updated><title type='text'>Little known, powerful APIs</title><content type='html'>Today, I'm working with an Exchange Event Sink. &lt;a href="http://www.codeproject.com/csharp/CsManagedEventSinksHooks.asp"&gt;This article&lt;/a&gt; is an invaluable source for starting things. It may not be complete, but I'd spend at least two weeks digging the Exchange SDK to accomplish the same thing.&lt;br /&gt;What I'm trying to do is a better integration between Exchange and Microsoft CRM. If this works, I'll publish it as an article. Microsoft CRM 1.2 standard e-mail support sucks: it needs a GUID on the subject with every message, it has no way of importing messages, the Exchange router is rudimentary at best.&lt;br /&gt;For me, an obvious way of integrating Microsoft CRM and Exchange would be: for every e-mail that comes to CRM accounts, lookup the CRM based on the e-mail address and associate it with the proper contact. Either I'll discover that this is a stupid way for some reason, or I'll come up with something better than Microsoft did. I rarely bet I can do anything better than MS, but this time I'm pretty sure of this...&lt;br /&gt;And what does this have to do with &lt;i&gt;"Little know, powerful APIs"&lt;/i&gt;? The lesson here is: never underestimate those lesser known APIs, like Exchange APIs. Some of these APIs are very powerful, and you can produce some powerful software. Since those APIs are known only by a few programmers, often you can produce softwares with very little competition, if any.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-111990309040986219?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/111990309040986219/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=111990309040986219' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111990309040986219'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111990309040986219'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/06/little-known-powerful-apis.html' title='Little known, powerful APIs'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-111929328012935743</id><published>2005-06-20T15:48:00.000-03:00</published><updated>2005-06-20T15:48:00.176-03:00</updated><title type='text'>Firefighting training simulations for testing code</title><content type='html'>I was watching this documentary about a new super cool firefighting training simulator, which was affordable enough that even small companies could use and that was very effective in detecting failures in firefighting procedures. Those failures, on real world situations, could lead to disasters, causing injuries and even deaths.&lt;br /&gt;&lt;br /&gt;So, an idea stroke me: what if we did the same thing in software world? &lt;br /&gt;&lt;br /&gt;I'll explain: most decent software companies now have a well-defined software testing process. But how can we detect problems on those testing procedures?&lt;br /&gt;Let's say we stopped a bit every now and then to make a bug detection simulation.&lt;br /&gt;&lt;br /&gt;One or two programmers would be responsible for intentionally introducing bugs that could cause a disaster. Only those programmers would know which bugs were introduced. The idea is making things fun, like a game, where those programmers try to break the testing process and the testing staff try to find those bugs as quickly as possible.&lt;br /&gt;&lt;br /&gt;A summary of the simulation would be:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;Establish a time limit for the simulation. There's no point in the exercise if it takes months to run. The idea is running it in around the same time it takes to assess if a build should go to the customer or not. If all the bugs are found too quickly, new bugs should be introduced.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;One or two programmers check-in some code that introduces some bugs. The more serious and disastrous the bugs are, the better. The harder to detect they are too, the better.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Those programmers may be allowed to alter the unit tests to make those bugs go unnoticed during the build process. I like the idea of being able to alter unit tests because that's what happens when you change specifications.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Without taking a look at the source code, the testing team will try to find those bugs.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;All the other programmers may also help the testing team to find those bugs.&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;After finding (or not) the bugs and finishing the simulation, a few things should be assessed:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;How fast did we detect those bugs?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Did we use the same procedures or did we need to employ new procedures?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Should we introduce new test procedures?&lt;/li&gt;&lt;br /&gt;&lt;li&gt;How many other bugs we found in the process? If we found bugs that were not part of the game, why didn't we find them before? What could we have done to find them?&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-111929328012935743?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/111929328012935743/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=111929328012935743' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111929328012935743'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111929328012935743'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/06/firefighting-training-simulations-for.html' title='Firefighting training simulations for testing code'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-111903192485218834</id><published>2005-06-17T15:12:00.000-03:00</published><updated>2005-06-17T15:12:04.853-03:00</updated><title type='text'>My own Daily WTF</title><content type='html'>What would you think of a programmer that coded an abstract class as a concrete class, and, instead of marking a few members abstract, implemented them as virtual and threw a "NotImplementedException"?&lt;br /&gt;Well, I can imagine your face, and yesterday I was strugling again with System.Net.WebRequest and its memory leaks, trying to implement a new HttpWebRequest that used only WinHTTP to eliminate memory leaks definitively from every WebServices call we have. The funny thing is: WebRequest is a class coded like that. Someone at MS certainly think it's brilliant coding like this, and throws NotImplementedException on their code, instead of marking their members abstract.&lt;br /&gt;A friend of mine here insisted that MS is not that bad at coding (and I do agree), and that there should be a good reason for that.&lt;br /&gt;Today, I was reading my RSS feeds, and I found this post at &lt;a href="http://thedailywtf.com/forums/36395/ShowPost.aspx"&gt;The Daily WTF&lt;/a&gt;, describing a similar situation...&lt;br /&gt;Sorry for my friend, but I really don't think that there's any good use for something like this.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-111903192485218834?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/111903192485218834/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=111903192485218834' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111903192485218834'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111903192485218834'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/06/my-own-daily-wtf.html' title='My own Daily WTF'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-111903142962529972</id><published>2005-06-17T15:03:00.000-03:00</published><updated>2005-06-17T15:03:49.646-03:00</updated><title type='text'>It's been a long time...</title><content type='html'>Since I last posted... But this blog is not abandoned, only neglected :)&lt;br /&gt;The truth is that I assumed the responsibility for both the sales and technical departments, and I was really tied to lots of meetings and understanding how I could make things work better, specially with our sales staff. Selling, instead of purely programming, is a new thing for me, and it's being great to grasp some sales concepts and gaining experience in another area. I've been programming since I was 11, this means that I am programming for 23 years as of now. I never worked with anything else, and go to sell my own software is a great experience, as I hear a lot of good things from our customers.&lt;br /&gt;But I still code a lot, and I'll update more this blog from now on&amp;#8230;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-111903142962529972?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/111903142962529972/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=111903142962529972' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111903142962529972'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/111903142962529972'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/06/its-been-long-time.html' title='It&apos;s been a long time...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-110838072430502804</id><published>2005-02-14T09:32:00.000-02:00</published><updated>2005-02-14T09:32:04.306-02:00</updated><title type='text'>It must be me.</title><content type='html'>I must have some kind of magnet inside my computer that attracts weird .NET framework bugs. Now, it's a random "The underlying connection was closed: An unexpected error occurred on a (send/receive)", when calling web services under stress.&lt;br /&gt;I googled a lot and I couldn't find something that solved my problem. Sure, I found a lot about HTTP Keep-alives and about proxies that dump the connection, but:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;I tried the KeepAlive = false solution, and it didn't work, as expected - MS says that solved this problem in one of the service packs.&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Proxies are not my problem. I am not passing through a proxy, neither accessing a remote machine. All the calls are being done on the same machine: the web service is simply a way for doing calls from a service to an ASP.NET application - kind of a sophisticated RPC&lt;/li&gt;&lt;br /&gt;&lt;li&gt;No exception is being thrown at the server side, and nothing appears on the Event Viewer&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;br /&gt;I must be doing something wrong. The trouble is: what? Crivo is quite sophisticated (over 220 projects), and this web service is a fa&amp;ccedil;ade for calling this code. &lt;b&gt;Anything&lt;/b&gt; can be the source of the problem. And I can't believe that web services are &lt;b&gt;that&lt;/b&gt; troublesome and not scalable to this point (I'm doing only 8 parallel calls).&lt;br /&gt;&lt;br /&gt;Sigh... It will be a long debugging and stress-testing week.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-110838072430502804?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/110838072430502804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=110838072430502804' title='12 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110838072430502804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110838072430502804'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/02/it-must-be-me.html' title='It must be me.'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-110805776011954920</id><published>2005-02-10T15:49:00.000-02:00</published><updated>2005-02-10T15:49:20.120-02:00</updated><title type='text'>I want to be a good programmer... How???</title><content type='html'>Yesterday, I was talking at CodeProject's Lounge, and &lt;a href="http://www.codeproject.com/lounge.asp?msg=1034867#xx1034867xx"&gt;someone asked&lt;/a&gt; about how to become a good programmer. It's actually a very good question, and I gave him the following answer:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;As with anything, time is the key. As the time passes, and you code, you'll get better. Don't expect to become a decent programmer in less than 4 years&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Find pet projects - even if you don't code a lot at college or at work, you can always get better by developing a project that you like. Don't worry if you will or won't be able to finish the project, and don't be scared about the size of the project. Even if you don't go too far in the project, you'll learn a lot&lt;/li&gt;&lt;br /&gt;&lt;li&gt;You'll make a lot of mistakes, like we did. And you'll learn from that. More than you'll learn from things you think you did right&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Read a lot the programming forums and newsgroups. Read every message: there are all kinds of programmers there, often with the same problems you'll face&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Try to find a more experienced programmer to tell you if your code is good or not (and why!). If you can't, use us on the forums. Post small pieces of code and ask "is there a better way of doing this?" or "can you suggest me style improvements?"&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Talking about style, programming is all about style. Don't dismiss a better solution just because "my code is ugly, but it just works"&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Start with a simpler, but robust language. I strongly suggest you to start with C# or Java. Forget about C++, VB, VB.NET, Perl, Python, etc, until you're better and can understand why&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Read a lot about "best practices": this way your path will be shorter, as you won't spend time doing the same mistakes we did&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Read a lot of books. Even those cheap "Learn * in 21 days" can be good for starters, but after a while, try to find better books&lt;/li&gt;&lt;br /&gt;&lt;li&gt;After a year programming, read a lot about OOP. This year without OOP will teach you why OOP is important&lt;/li&gt;&lt;br /&gt;&lt;li&gt;After a year of OOP programming, read a lot about design patterns. This year without design patterns will teach you why design patterns are important&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Google is your friend. You need to be a Google master. Any good programmer should be able to find the needed information quickly&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Don't be ashamed to try things: "What if I cast this double variable to a char * ?". After you see things like this not working, try to understand why&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Karl suggested that I made this an article. I like the idea, and probably I'll expand those items and add a few other items.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-110805776011954920?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/110805776011954920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=110805776011954920' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110805776011954920'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110805776011954920'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/02/i-want-to-be-good-programmer-how.html' title='I want to be a good programmer... How???'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-110798867254458728</id><published>2005-02-09T20:37:00.000-02:00</published><updated>2005-02-09T20:37:52.543-02:00</updated><title type='text'>Exception Handling Best Practices in .NET</title><content type='html'>"My software never fails". Can you believe it? I'm almost hearing you all, screaming that I'm a liar. "Software that never fails is something near to impossible!"&lt;br /&gt;Contrary to common belief, creating reliable, robust software is not something near to impossible. Notice that I'm not referring to bug-free software, intended to control nuclear power plants. I'm referring to common business software, which can run unattended on a server, or even a desktop machine, for long periods of time (weeks or months) and work predictably without any significant glitch. By predictably, I mean that it has a low failure rate, you can easily understand failure conditions to fix it quickly, and it never damages data in response of an external failure.&lt;br /&gt;In other words, software that is stable.&lt;br /&gt;Having a bug in your software is forgivable, and even expected. What's unforgivable is having a recurring bug you can't fix because you don't have enough information.&lt;br /&gt;To understand better what I'm saying, I've seen countless business software that, in an out of disk space error in the DBMS, reports something like this:&lt;br /&gt;"Could not update customer details. Contact the system administrator and try again later".&lt;br /&gt;While this message may be an adequate of reporting an unknown resource failure to a business user, all too often this is the whole debugging information that is available to debug the error cause. Nothing was logged, and understanding what is happening will be time-consuming and often programmers will guess a lot of possible causes until they find the real error cause.&lt;br /&gt;Notice that in this article, I will concentrate only in how to make a better use of .NET exceptions: I won't discuss how to properly report error messages, because I believe this belongs to UI domain, and it depends heavily on the interface being developed and the target audience; a blog text editor targeting teenagers should report error messages in a way completely different than a socket server, which will only be used directly by programmers.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Plan for the worst&lt;/h2&gt;&lt;br /&gt;A few basic design concepts will make your program much more robust, and will improve the user experience in the presence of an unexpected error. What do I mean by "improve the user experience in the presence of an unexpected error"? It's not that the user will be thrilled by the marvelous dialog box you'll show him. It's more about don't corrupting data, don't crashing the computer, and behaving safely. If your program can pass through an out of disk space error without doing any harm, you improved the user experience.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Check it early&lt;/h3&gt;&lt;br /&gt;Strong type checking and validation are powerful tools to prevent unexpected exceptions and to document and test code. The earlier in execution you detect a problem, the easier is to fix. Trying to understand what a CustomerID is doing on the ProductID column on the InvoiceItems table after a few months isn't fun neither easy. If you used classes for storing customer data, instead of using primitives (e.g., int, string, etc), chances are that the compiler would never allow you to do such a thing.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't trust external data&lt;/h3&gt;&lt;br /&gt;External data is not reliable. It must be extensively checked. It doesn't matter if the data is coming from the registry, database, from a disk, from a socket, from a file you just wrote or from the keyboard. All external data should be checked and only then you can rely on it. All too often I see programs that trust configuration files because the programmer never thought that someone would edit the file and corrupt it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;The only reliable devices are: the video, the mouse and keyboard.&lt;/h3&gt;&lt;br /&gt;Anytime you need external data, you can have the following situations:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Not enough security privileges&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The information is not there&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The information is incomplete&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The information is complete, but invalid&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;It really doesn't matter if it's a registry key, a file, a socket, a database, a web service or a serial port. All external data sources will fail, sooner or later. Plan for a safe failure and minimize damage. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Writes can fail, too&lt;/h3&gt;&lt;br /&gt;Unreliable data sources are also unreliable data repositories. When you're saving data, similar situations can happen:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Not enough security privileges&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The device isn't there&lt;/li&gt;&lt;br /&gt;&lt;li&gt;There's not enough space&lt;/li&gt;&lt;br /&gt;&lt;li&gt;The device has a physical fault&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;That's why compression programs create a temporary file and rename it after they're done, instead of changing the original one: if the disk (or even the software) fails for some reason, you won't lose your original data.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Code Safely&lt;/h2&gt;&lt;br /&gt;A friend of mine often says: "A good programmer is someone who never introduce bad code in his projects". I don't believe that this is all that it's needed to be a good programmer, but surely it will put you almost there. Below, I compiled a list of the most common "bad code" that you can introduce in your projects, when it comes to exception handling.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't throw new Exception()&lt;/h3&gt;&lt;br /&gt;Please, don't do it. Exception is a too broad class, and it's hard to catch without side-effects. Derive your own exception class, but derive it from ApplicationException. This way you could set a specialized exception handler for exceptions thrown by the framework and another for exceptions thrown by yourself.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't put important exception information on the Message field&lt;/h3&gt;&lt;br /&gt;Exceptions are classes. When you return the exception information, create fields to store data. If you fail on doing it, people will need to parse the Message field to get the information they need. Now, think what will happen to the calling code if you need to localize or even just correct a spelling error in error messages. You may never know how much code you'll break by doing it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Put a single catch (Exception ex) per thread&lt;/h3&gt;&lt;br /&gt;Generic exception handling should be done in a central point in your application. Each thread needs a separate try/catch block, or you'll lose exceptions and you'll have problems hard to understand. When an application starts several threads to do some background processing, often you create a class for storing processing results. Don't forget to add a field for storing an exception that could happen or you won't be able to communicate it to the main thread. In "fire and forget" situations, you probably will need to duplicate the main application exception handler on the thread handler.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Generic Exceptions caught should be published&lt;/h3&gt;&lt;br /&gt;It really doesn't matter what you use for logging - log4net, EIF, Event Log, TraceListeners, text files, etc. What's really important is: if you caught a generic Exception, log it somewhere. But log it only once - often code is ridden with catch blocks that log exceptions and you end up with a huge log, with too much repeated information to be useful.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Log Exception.ToString(); never log only Exception.Message!&lt;/h3&gt;&lt;br /&gt;As we're talking about logging, don't forget that you should always log Exception.ToString(), and never Exception.Message. Exception.ToString() will give you a stack trace, the inner exception and the message. Often, this information is priceless and if you only log Exception.Message, you'll only have something like .&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't catch (Exception) more than once per thread&lt;/h3&gt;&lt;br /&gt;There are rare exceptions (no pun intended) to this rule. If you need to catch an exception, always use the most specific exception for the code you're writing.&lt;br /&gt;I always see beginners thinking that good code is code that doesn't throw exceptions. This is not true. Good code throws exceptions as needed, and handles only the exceptions it knows how to handle.&lt;br /&gt;As a sample of this rule, look at the code below. I bet that the guy who wrote it will kill me when he read this, but it was taken from a real-world example. Actually, the real-world code was a bit more complicated - I simplified it a lot for didactic reasons.&lt;br /&gt;The first class (MyClass) is on an assembly, and the second class (GenericLibrary) is on another assembly, a library full of generic code. On the development machine the code ran right, but on the QA machines, the code always returned "Invalid number", even if the entered number was valid.&lt;br /&gt;&lt;br /&gt;Can you say why this was happening?&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;class&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; MyClass&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ValidateNumber&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; userInput&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; val &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GenericLibrary&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ConvertToInt&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;userInput&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Valid number"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Exception&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Invalid number"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;class&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GenericLibrary&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ConvertToInt&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; userInput&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Convert&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ToInt32&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;userInput&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;The problem was the too generic exception handler. According to the MSDN documentation, Convert.ToInt32 only throws ArgumentException, FormatException and OverflowException. So, those are the only exceptions that should be handled.&lt;br /&gt;The problem was on our setup, which didn't include the second assembly (GenericLibrary). Now, we had a FileNotFoundException when the ConvertToInt was called, and the code assumed that it was because the number was invalid.&lt;br /&gt;The next time you write "catch (Exception ex)", try to describe how your code would behave when an OutOfMemoryException is thrown.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't ever swallow exceptions&lt;/h3&gt;&lt;br /&gt;The worst thing you can do is catch (Exception) and put an empty code block on it. Never do it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Cleanup code should be put in finally blocks&lt;/h3&gt;&lt;br /&gt;Ideally, since you're not handling a lot of generic exceptions and have a central exception handler, your code should have a lot more finally blocks than catch blocks. Never do cleanup code, e.g., closing streams, restoring state (as the mouse cursor), outside of a finally block. Make it a habit.&lt;br /&gt;&lt;br /&gt;One thing that people often overlook is how a try/finally block can make your code both more readable and more robust. It's a great tool for cleanup code.&lt;br /&gt;As a sample, suppose you need to read some temporary information from a file and return it as a string. No matter what happens, you need to delete this file, because it's temporary. This kind of return &amp; cleanup begs for a try/finally block. &lt;br /&gt;&lt;br /&gt;Let's see the simplest possible code without using try/finally:&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        fileContents &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;This code also has a problem when an exception is thrown on, e.g., the ReadToEnd method: it leaves a temporary file on the disk. So, I've actually saw some people trying to solve it coding as this:&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            fileContents &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Exception&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;throw&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;The code is becoming complex and it's starting to duplicate code.&lt;br /&gt;&lt;br /&gt;Now, see how much cleaner and robust is the try/finally solution:&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;finally&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;Where did the fileContents variable go? It's not necessary anymore, because we can return the contents and the cleanup code executes after the return point. This is one of the advantages of having code that can run &lt;b&gt;after&lt;/b&gt; the function returns: you can clean resources that may be needed for the return statement.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Use "using" everywhere&lt;/h3&gt;&lt;br /&gt;Simply calling Dispose() on an object is not enough. The "using" keyword will prevent resource leaks even on the presence of an exception.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't return special values on error conditions&lt;/h3&gt;&lt;br /&gt;There are lots of problems with special values:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Exceptions makes the common case faster, because when you return special values from methods, each method return needs to be checked and this consumes at least one processor register more, leading to slower code&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Special values can, and will, be ignored&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Special values don't carry stack traces, and rich error details. There are performance reasons, too&lt;/li&gt;&lt;br /&gt;&lt;li&gt;All too often there's no suitable value to return from a function that can represent an error condition. What value would you return from the function below to represent a "division by zero" error?&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; divide&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; x&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; y&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; x &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;/&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; y&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't use exceptions to indicate absence of a resource&lt;/h3&gt;&lt;br /&gt;Microsoft recommends you to use return special values on extremely common situations. I know I just said the opposite and I also don't like it, but life is easier when most APIs are consistent, so I recommend you to adhere to this style with caution.&lt;br /&gt;If looked at the .NET framework, and I noticed that the only APIs that follow this style are the APIs that return some resource (e.g., Assembly.GetManifestStream method). All those APIs return null in case of the absence of some resource.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't use exception handling as means of returning information from a method&lt;/h3&gt;&lt;br /&gt;This is a bad design. Not only exceptions are slow (as the name implies, they're meant only to be used on exceptional cases), but a lot of try/catch blocks in your code makes the code harder to follow. Proper class design can accommodate common return values. If you're really in need to return data as an exception, probably your method is doing too much and needs to be split.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Use exceptions for errors that should not be ignored&lt;/h3&gt;&lt;br /&gt;I'll use a real world example for this. When developing an API so people could access Crivo (my product), the first thing that you should do is calling the Login method. If Login fails, or is not called, every other method call will fail. I throw an exception from the Login method if it fails, so the calling program cannot ignore it.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't clear the stack trace when re-throwing an exception&lt;/h3&gt;&lt;br /&gt;The stack trace is one of the most useful information that an exception carries. Often, we need to put some exception handling on catch blocks (e.g., to rollback a transaction) and re-throw the exception. See the right (and the wrong) way of doing it:&lt;br /&gt;&lt;br /&gt;The wrong way:&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;       &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// Some code that throws an exception&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Exception ex&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// some code that handles the exception&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;throw&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ex&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;Why is this wrong? Because, when you examine the stack trace, the point of the exception will be the line of the "throw ex;", hiding the real error location. Try it.&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;       &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// Some code that throws an exception&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Exception ex&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// some code that handles the exception&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;throw&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;What has changed? Instead of "throw ex;", which will throw a new exception and clear the stack trace, we have simply "throw;". If you don't specify the exception, the throw statement will simply rethrow the very same exception the catch statement caught. This will keep your stack trace intact, but still allows you to put code in your catch blocks.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Avoid changing exceptions without adding semantic value&lt;/h3&gt;&lt;br /&gt;Only change an exception if you need to add some semantic value to it - e.g., you're doing a DBMS connection driver, so the user doesn't care about the specific socket error, the user wants only to know that the connection failed. &lt;br /&gt;If you ever need to do it, please, keep the original exception on the InnerException member. Don't forget that your exception handling code may have a bug too, and if you have InnerException, you may be able to find it easier.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Exceptions should be marked [Serializable]&lt;/h3&gt;&lt;br /&gt;A lot of situations needs that exceptions are serializable. When deriving from another exception class, don't forget to add that attribute.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;When in doubt, don't Assert, throw an Exception&lt;/h3&gt;&lt;br /&gt;Don't forget that Debug.Assert is removed from release code. When checking and doing validation, it's often better to throw an Exception than to put an assertion in your code.&lt;br /&gt;Save assertions for unit tests, for internal loop invariants, and for checks that should never fail due to runtime conditions (a very rare situation, if you think about it).&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Each exception class should have at least the three original constructors&lt;/h3&gt;&lt;br /&gt;Doing it is easy (just copy &amp; paste the definitions from other exception classes) and failing to do that won't allow users of your classes to follow some of these guidelines.&lt;br /&gt;Which constructors I am referring to? The last three constructors described on &lt;A HREF="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemExceptionClassctorTopic1.asp"&gt;this page&lt;/A&gt;.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Don't reinvent the wheel&lt;/h2&gt;&lt;br /&gt;There are lots of good frameworks and libraries to deal with exceptions. Two of them are provided by Microsoft and I mention here:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;&lt;A HREF="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=8CA8EB6E-6F4A-43DF-ADEB-8F22CA173E02"&gt;Exception Management Application Block&lt;/A&gt;&lt;/li&gt;&lt;br /&gt;&lt;li&gt;&lt;A HREF="http://www.microsoft.com/downloads/details.aspx?FamilyId=80DF04BC-267D-4919-8BB4-1F84B7EB1368&amp;displaylang=en"&gt;Microsoft Enterprise Instrumentation Framework&lt;/A&gt;&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Notice, though, that if you don't follow strict design guidelines, like those I showed here, those libraries will be nearly useless.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;VB.NET&lt;/h2&gt;&lt;br /&gt;If you read through this article, you'll notice that all the samples I used were in C#. That's because C# is my preferred language, and because VB.NET has a few guidelines of its own. &lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Emulate C# "using" statement&lt;/h3&gt;&lt;br /&gt;Unfortunately, VB.NET still doesn't have the "using" statement. Whidbey will has it, but until it's there, everytime you need to dispose an object, you should use the following pattern:&lt;br /&gt;&lt;br /&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Dim&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sw &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;As&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamWriter &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Nothing&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            sw &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;New&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamWriter(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;"C:\crivo.txt"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;' Do something with sw&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Finally&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;If&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Not&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sw &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;is&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Nothing&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Then&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                sw.Dispose()&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;End&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;if&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;End&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;Finally&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;br /&gt;If you're doing something different when calling Dispose, probably you're doing something wrong, and your code can fail and/or leak resources.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Don't use Unstructured Error Handling&lt;/h3&gt;&lt;br /&gt;Unstructured Error Handling is also known as "On Error Goto". Prof. Djikstra did it very well in 1974 when he wrote &lt;i&gt;"Go To statement considered harmful"&lt;/i&gt;. It was more than 30 years ago. Please, remove all traces of Unstructured Error Handling from your application as soon as possible. "On Error Goto" statements will bite you, I'll assure you.&lt;br /&gt;&lt;br /&gt;&lt;h2&gt;Conclusion&lt;/h2&gt;&lt;br /&gt;I hope that this article helps someone to code better. More than a closed list of practices, I hope that this article be a starting point for a discussion of how to deal with exceptions in our code, and how to make our programs more robust.&lt;br /&gt;I can't believe that I wrote all of this without any error or controversial opinion. I'd love to hear your opinion and suggestions about this topic.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-110798867254458728?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/110798867254458728/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=110798867254458728' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110798867254458728'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/110798867254458728'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2005/02/exception-handling-best-practices-in.html' title='Exception Handling Best Practices in .NET'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109421265277970285</id><published>2004-09-03T08:57:00.000-03:00</published><updated>2004-09-03T08:57:32.780-03:00</updated><title type='text'>And they said to you "no one will do drivers in .NET"</title><content type='html'>&lt;a href="http://ati.com/products/catalystcontrolcenter/index.html"&gt;Ok, it's only the control center&lt;/a&gt;, but it's a start... And it's from ATI, what means that soon any machine with an ATI card will have the .NET framework installed.&lt;br /&gt;&lt;br /&gt;&lt;a href="http://weblogs.asp.net/psteele/archive/2004/09/02/224879.aspx"&gt;Via Patrick Steele's .NET Blog&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109421265277970285?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109421265277970285/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109421265277970285' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109421265277970285'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109421265277970285'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/09/and-they-said-to-you-no-one-will-do.html' title='And they said to you &quot;no one will do drivers in .NET&quot;'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109421022333904336</id><published>2004-09-03T08:17:00.000-03:00</published><updated>2004-09-05T20:59:40.256-03:00</updated><title type='text'>GMail</title><content type='html'>Thanks to &lt;a href="http://weblogs.asp.net/dstone/"&gt;David Stone&lt;/a&gt;, I'm a proud &lt;a href="http://gmail.goole.com/"&gt;GMail&lt;/a&gt; user. Since I run my own Exchange server, the 1GB is not my primary interest (although I have some friends that loved it!). Most of my interest on it is learning how to do a lightining-fast, cleanly designed, cross browser UI.&lt;br /&gt;If you are interested in a Google mail account, Google gave me 12 invites, and I already spent 6 of them. If you want it, drop me a comment or an e-mail with your e-mail address (don't forget to obfuscate it, beware of spambots) an your name, and I'll invite you.&lt;br /&gt;[Update: now only 3 to go...]&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109421022333904336?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109421022333904336/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109421022333904336' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109421022333904336'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109421022333904336'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/09/gmail.html' title='GMail'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109403950262351251</id><published>2004-09-01T08:51:00.000-03:00</published><updated>2004-09-01T08:51:42.623-03:00</updated><title type='text'>SoapInclude &amp; XmlInclude</title><content type='html'>Yesterday, I coded a webservice that needed to return an array of objects that derived from a common base (abstract) class. When I tried to access the webservice, I had the following message:&lt;br /&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;The type XXX.YYY was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.&lt;/i&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;I thought: "Doh! Sure! ASP.NET needs to know about all the concrete classes, not only about the base class to be able to generate a proper WSDL, so a proper proxy client can be generated. Simple! Just add a SoapInclude(typeof()) attribute for each of the concrete classes and there we go!".&lt;br /&gt;And so I did it. It didn't work.&lt;br /&gt;I copy &amp; pasted the &lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemxmlserializationsoapattributesclasssoapattributetopic.asp"&gt;MSDN sample for the SoapInclude attribute&lt;/a&gt;. It didn't work.&lt;br /&gt;I tried it on a machine without SP1. It didn't work.&lt;br /&gt;I tried to add the SoapInclude() attribute on the base class. It didn't work.&lt;br /&gt;On a desperate try, I remove all the SoapInclude() attributes and used XmlInclude() attributes (remember the error message)? &lt;b&gt;Yeah! It worked!&lt;/b&gt;&lt;br /&gt;So, I leave this for anyone who may have the same problem and find me through Google or who can explain me why the SoapInclude() attribute didn't work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109403950262351251?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109403950262351251/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109403950262351251' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109403950262351251'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109403950262351251'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/09/soapinclude-xmlinclude.html' title='SoapInclude &amp; XmlInclude'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109403890134535286</id><published>2004-09-01T08:41:00.000-03:00</published><updated>2004-09-01T08:41:41.346-03:00</updated><title type='text'>Installing .NET 1.1 SP1 and Resharper 108</title><content type='html'>You can find Microsoft .NET Framework 1.1 Service Pack 1 &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=A8F5654F-088E-40B2-BBDB-A83353618B38&amp;displaylang=en"&gt;here&lt;/a&gt; and a version for Windows Server 2003 &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=AE7EDEF7-2CB7-4864-8623-A1038563DF23&amp;displaylang=en"&gt;here&lt;/a&gt;.&lt;br /&gt;I installed it yesterday and it required a reboot (probably because I was running RSS Bandit, coded in C#). After the reboot, my Resharper trial  (build 108) didn't work anymore, giving me a strange HRESULT.&lt;br /&gt;My solution:&lt;br /&gt;When VS.NET asked about removing Resharper, I chose "No". Then, I removed Resharper through "Add/Remove Programs" and reinstalled it. Everything went back to normal.&lt;br /&gt;And why am I saying this? While everything seems fine with my software, it tastes bad. Something in .NET SP1 installation broke Resharper, a .NET application just like mine. Why? What broke? It's hard to say that Jetbrains did something wrong on Resharper that would break on a service pack installation (contrary to &lt;a href="http://software.ericsink.com/entries/false_alarm.html"&gt;Vault&lt;/a&gt;, which used a poor design decision). Sooner or later (probably when this gets into Windows Update), my customers will upgrade to SP1 and this may happen to them. We have people testing our software under SP1 (heck, even my machine is running it), but I won't feel comfortable until a lot of people upgrade.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109403890134535286?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109403890134535286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109403890134535286' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109403890134535286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109403890134535286'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/09/installing-net-11-sp1-and-resharper.html' title='Installing .NET 1.1 SP1 and Resharper 108'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109214002239591389</id><published>2004-08-10T09:13:00.000-03:00</published><updated>2004-08-10T09:13:42.403-03:00</updated><title type='text'>I installed XP SP2</title><content type='html'>So far, nothing broke. I had a pretty stable installation before this, and now, too. I've had two GPFs with zip folders (and didn't in XP SP1), but it seems to work. IE6 seems way better, but I really don't use it for navigation anymore, only for a bit of ASP.NET development (I only use Firefox for navigation, as I'm addicted to tabbed browsing, mouse gestures and adblock). &lt;br /&gt;My software used some popups for drill-down in reports, and had those windows blocked. Exception lists are just two clicks aways, so, it won't be a problem.&lt;br /&gt;The firewall asked me if RSS Bandit should be allowed to navigate, and while it seems to be the correct behavior, it didn't ask the same thing for AVG antivirus. Maybe it's something I didn't understand yet about it.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109214002239591389?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109214002239591389/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109214002239591389' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109214002239591389'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109214002239591389'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/08/i-installed-xp-sp2.html' title='I installed XP SP2'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109171449371561329</id><published>2004-08-05T11:01:00.000-03:00</published><updated>2004-08-05T11:01:33.723-03:00</updated><title type='text'>A weird bug - This time I don't know where, but solved it</title><content type='html'>I'm deploying this Windows Forms application, which is actually a simple, but pretty text editor with some features like Intelissense and syntax highlighting. The application was tested on lots of environments and still, it managed to not work on any of the customer's computers. The culprit was the following innocent line:&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;MyFont &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Font&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Courier New"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 10&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;Strange as it may seem, it was throwing the following exception:&lt;pre&gt;************** Exception Text **************&lt;br /&gt;System.TypeInitializationException: The type initializer &lt;br /&gt;for "ICSharpCode.TextEditor.Document.FontContainer" threw an exception. ---&gt; &lt;br /&gt;System.ArithmeticException: Overflow or underflow in the arithmetic operation.&lt;br /&gt;   at System.Drawing.Font.Initialize(FontFamily family, Single emSize, &lt;br /&gt;FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)&lt;br /&gt;   at System.Drawing.Font.Initialize(String familyName, Single emSize, &lt;br /&gt;FontStyle style, GraphicsUnit unit)&lt;br /&gt;   at System.Drawing.Font..ctor(String familyName, Single emSize)&lt;/pre&gt;&lt;br /&gt;After a lot of Googling I found &lt;a href="http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219"&gt;this KB article&lt;/a&gt; which mentions a similar problem and a possible solution. It was pretty close to the solution, but it didn't work. It seems to be some other software or driver interfering with my .NET application. I blame it on their anti-virus, as we tested it on lots of different hardware and software configurations (notebooks, desktops, developer machines) and none of them worked, but the same corporate anti-virus was present at all of these machines.&lt;br /&gt;Since I cannot tell them to disable their anti-virus, lots and lots of desperate Googling (and the customer in need of the application), what I ended up doing was:&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    DefaultFont &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Font&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Courier New"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 10&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ArithmeticException&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    ResetFPU&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    DefaultFont &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Font&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Courier New"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 10&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;where &lt;b&gt;ResetFPU&lt;/b&gt; stands for:&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"msvcr70.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CallingConvention &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CallingConvention&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Cdecl&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _controlfp&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; n&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; mask&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _RC_NEAR       &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000000&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _PC_53         &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00010000&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_INVALID    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000010&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_UNDERFLOW  &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000002&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_ZERODIVIDE &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000008&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_OVERFLOW   &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000004&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_INEXACT    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000001&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_DENORMAL   &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00080000&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _CW_DEFAULT    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _RC_NEAR &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _PC_53 &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    _EM_INVALID &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_ZERODIVIDE &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_OVERFLOW &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_UNDERFLOW &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    _EM_INEXACT &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; _EM_DENORMAL&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ResetFPU&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    _controlfp&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;_CW_DEFAULT &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;0xfffff&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;I hope this helps someone in the future...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109171449371561329?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109171449371561329/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109171449371561329' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109171449371561329'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109171449371561329'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/08/weird-bug-this-time-i-dont-know-where.html' title='A weird bug - This time I don&apos;t know where, but solved it'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109093196684864560</id><published>2004-07-27T09:39:00.000-03:00</published><updated>2004-07-27T09:39:26.856-03:00</updated><title type='text'>Switched to a full RSS feed - Dog Food</title><content type='html'>It may seem weird, but I did not try my own Atom Feed until today. When I saw it, I noticed: it was ugly, without formatting, without the source code, and incomplete. I changed a simple setting on Blogger.com and then, bang! Instant full RSS feeds, with colors, fonts, links and all the text!&lt;br /&gt;I hope this does not be a hassle, but I love reading full RSS feeds, so I thought this switch was a Good Thing.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109093196684864560?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109093196684864560/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109093196684864560' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109093196684864560'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109093196684864560'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/switched-to-full-rss-feed-dog-food.html' title='Switched to a full RSS feed - Dog Food'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109085119401065073</id><published>2004-07-26T11:13:00.000-03:00</published><updated>2004-07-26T11:13:14.023-03:00</updated><title type='text'>FlexWiki installed</title><content type='html'>We are already using CVS, NAnt, NUnit and &lt;a href="http://www.bugzilla.org/"&gt;Bugzilla&lt;/a&gt; for quite a long time and we have a very good history  with these tools. They're solid rock stable, useful, and some are even intuitive (e.g., Bugzilla). Bugzilla was a bit strange to setup, mainly because I do play a bit with Linux, but I'm by no means a Linux wizard.&lt;br /&gt;People here liked &lt;a href="http://www.bugzilla.org/"&gt;Bugzilla &lt;/a&gt; so much that they started to create bugs in it just to document some  internal knowledge and procedures (e.g., "how to setup a new build machine").&lt;br /&gt;So I installed &lt;a href="http://www.flexwiki.com/default.aspx/FlexWiki.FlexWiki"&gt;FlexWiki&lt;/a&gt;. It took me around 10 minutes to download and setup it.&lt;br /&gt;We're still moving all the scattered documentation to the Wiki, but it seems great. FlexWiki have a few bugs, but at least until now, nothing seems so serious that makes it not be a great tool to use.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109085119401065073?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109085119401065073/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109085119401065073' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109085119401065073'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109085119401065073'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/flexwiki-installed.html' title='FlexWiki installed'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109066377840849901</id><published>2004-07-24T07:09:00.000-03:00</published><updated>2004-07-24T07:09:38.413-03:00</updated><title type='text'>Where did my code go?</title><content type='html'>A few weeks ago, I was teaching a bit of modern OO design to a fellow programmer (a bit of UML, design patterns, code smells, refactor, etc), who is one of the best programmers I've ever knew (he coded so many things other people named "impossible" that one has to respect that). For a series of reasons, he never really did a whole OO design, and he needed to design this big system, with around 50 classes. One of the difficulties was that he was having a bad time, trying to understand where all the code he was originally planning to do gone. All those huge methods he was planning to do had simply disappeared! Now, he basically had a few, very small methods (the biggest was around 10 or 20 lines of code), and the logic was scattered all over the place! He could clearly see that the design was right, and that the final code would probably work, but he was with that constant feeling that "we left something out of this", "the code can't be that simple", and so on.&lt;br /&gt;And why I am talking about all of this? I'm reading Fowler's &lt;i&gt;"Refactoring: Improving Design of Existing Code"&lt;/i&gt;, and here is something I'd like to quote:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;The object programs that live best and longest are those with short methods. Programmers new to objects often feel that no computation ever takes place, that object programs are endless sequences of delegation. When you have lived with such a program for a few years, however, you learn just how valuable all those little methods are.&lt;/i&gt; - Martin Fowler&lt;/blockquote&gt;&lt;br /&gt;Well, at least is nice to see that other people experience the same things.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109066377840849901?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109066377840849901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109066377840849901' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109066377840849901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109066377840849901'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/where-did-my-code-go.html' title='Where did my code go?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109041673643485025</id><published>2004-07-21T10:32:00.000-03:00</published><updated>2004-07-21T11:01:31.983-03:00</updated><title type='text'>More about the HttpWebRequest/HttpWebResponse leaks</title><content type='html'>Steve Binney contacted me through e-mail and provided some feedback about the &lt;a href="http://dturini.blogspot.com/2004/06/on-past-few-days-im-dealing-with-some.html"&gt;.NET HTTP infrastructure leaks&lt;/a&gt; I've (actually, everyone have) been having. The two last e-mails I had from him provided some very useful observations about the bug:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Email #1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;Daniel, &lt;br /&gt;&lt;br /&gt;I decided to be brave and install .Net 1.1 SP1 on my laptop.  Unfortunately,  the leaks still seem to be there.  In Reflector, I have verified the HttpWebResponse/Request still have the leaks. &lt;br /&gt;&lt;br /&gt;Steve&lt;/i&gt;&lt;/blockquote&gt;&lt;i&gt;&lt;b&gt;Email #2&lt;/b&gt;&lt;/i&gt;&lt;blockquote&gt;&lt;i&gt;To clarify my observations: &lt;br /&gt;&lt;br /&gt;On the released version of .Net 1.1 and .Net 1.1 sp1 beta: &lt;br /&gt;&lt;br /&gt;My app makes one synchronous HttpWebRequest/HttpWebResponse per second on a single thread.  My handle count starts at 200 and ramps up to approx. 1200 before automatic GC kicks in.  Memory (private bytes) start at 7 mb and quickly ramps to 20 mb before leveling off.  The memory slowly creeps up after that.    On a few occasions, the memory quickly increased to 60 mb but I cannot reproduce this.  Calling gc.Collect stops the handle leak but has no effect on memory. &lt;br /&gt;&lt;br /&gt;On VS 2005 Beta 1, .Net 2.0 beta 1: &lt;br /&gt;Memory and handles are constant at (&amp;lt; 200 handles) and (18 mb).  Using reflector, I see that the  HttpWebRequest/HttpWebResponse clean up the &lt;br /&gt;event  handles created by internally calling begin/end async  methods. &lt;br /&gt;&lt;br /&gt;Steve&lt;/i&gt;&lt;/blockquote&gt;&lt;br /&gt;I have mixed feelings about this input: while it's very good news that VS 2005 does not have the same leaks, I feel a bit frustrated that this bug is not fixed yet in the .NET 1.1 SP1.&lt;br /&gt;Steve and I also posted this on &lt;a href="http://groups.google.com/groups?dq=&amp;hl=en&amp;lr=&amp;ie=UTF-8&amp;threadm=%2352macEaEHA.1768%40TK2MSFTNGP10.phx.gbl&amp;rnum=1&amp;prev=/groups%3Fdq%3D%26start%3D25%26hl%3Den%26lr%3D%26ie%3DUTF-8%26group%3Dmicrosoft.public.dotnet.framework%26selm%3D%252352macEaEHA.1768%2540"&gt;microsoft.public.dotnet.framework&lt;/a&gt;, but by Feroze feedback I feel it'll be a long, long run until a solution. Feroze didn't even seem to have looked at or tried the 10-line code snippet I posted. Probably I'll be using .NET 2.0 before that is fixed...&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109041673643485025?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109041673643485025/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109041673643485025' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109041673643485025'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109041673643485025'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/more-about-httpwebrequesthttpwebrespon.html' title='More about the HttpWebRequest/HttpWebResponse leaks'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-109040657678034558</id><published>2004-07-21T07:42:00.000-03:00</published><updated>2004-07-21T07:42:56.790-03:00</updated><title type='text'>Boo</title><content type='html'>No, I'm not talking about the little girl from &lt;a href="http://www.imdb.com/title/tt0198781/"&gt;Monsters, Inc&lt;/a&gt;. I'm talking about Rodrigo Barreto de Oliveira's work on a new language called &lt;a href="http://boo.codehaus.org/"&gt;Boo&lt;/a&gt;, defined as a "wrist friendly language" on &lt;a href="http://boo.codehaus.org/BooManifesto.pdf"&gt;its manifesto&lt;/a&gt;. Boo borrows some ideas from other languages (e.g., "duck typing" is nothing more than the old "late binding"), but introduces several new concepts (at least, new to me):&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Extensible compilation pipeline: you can extend the language by implementing a visitor&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Syntatic macros: it's not really new, but I didn't see anything like this since Clipper 5.x preprocessor, which allowed you to create your own keywords&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Syntatic attributes: cool idea, similar to syntatic macros&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Delegates are simpler than in C# and VB.NET: you can treat any function as an object&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Automatic return type inference: only to save a little typing, but it's clean&lt;/li&gt;&lt;br /&gt;&lt;li&gt;String interpolation: Rodrigo surely coded in Clipper in the past&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Builtin Literals: some ideas seem to come from Perl&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;There are some things, I don't like, though:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;Automatic type conversion: aka "Option Strict Off" on VB.NET - I hate that!&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Automatic variable declaration: for it to work, it needs a very solid IDE that's able to catch typos, or it'll introduce bugs that even with unit test may be hard to find out&lt;/li&gt;&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;But the coolest things about this language are:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt;It's .NET friendly, so you can start using it now where it makes sense to produce some C#-callable libraries&lt;/li&gt;&lt;br /&gt;&lt;li&gt;Hey, it's from a Brazilian buddy! It's always nice to see some yellow &amp;amp; green language design!&lt;/li&gt;&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-109040657678034558?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/109040657678034558/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=109040657678034558' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109040657678034558'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/109040657678034558'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/boo.html' title='Boo'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108920218559780360</id><published>2004-07-07T09:09:00.000-03:00</published><updated>2004-07-07T10:44:17.083-03:00</updated><title type='text'>Another bug, another workaround...</title><content type='html'>I was using &lt;a href="http://www.sellsbrothers.com/tools/genghis/"&gt;Genghis&lt;/a&gt; to create a standard Find and Replace dialog, when I hit another bug  in the .NET framework (this is getting boring...):&lt;br /&gt;The System.Windows.Forms.NativeWindow class has a problem on the ReleaseHandle method: I don't know (don't care) why, when you subclass a window using the NativeWindow class, your new WndProc will still be called, even after the ReleaseHandle. On the Genghis FindReplaceDialog class, this bug appears when you invoke the dialog twice: your WndProc will be called for a while, and then, BAM! A call to a collected delegate will happen. I googled a lot and found nothing, so I coded the following workaround. When you need to subclass a window, just derive from my class instead of deriving from System.Windows.Forms.NativeWindow class and you won't need to change a single line of code!&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;class&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; NativeWindow&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr handle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WndProcDelegate wndProcDelegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// Prevents the delegate being collected&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr oldWndFunc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;delegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr WndProcDelegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr hwnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr wParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr lParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GWL_WNDPROC &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;-&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;4&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"User32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr SetWindowLong&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; nIndex&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WndProcDelegate wndProcDelegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"User32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr SetWindowLong&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; nIndex&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr wndFunc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"User32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr CallWindowProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr prevWndFunc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; iMsg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr wParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr lParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; NativeWindow&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        wndProcDelegate &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WndProcDelegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;this&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;WndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; AssignHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        handle &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        oldWndFunc &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; SetWindowLong&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GWL_WNDPROC&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; wndProcDelegate&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReleaseHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        SetWindowLong&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;handle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GWL_WNDPROC&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; oldWndFunc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        handle &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        oldWndFunc &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;protected&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;virtual&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;ref&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Message msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        DefWndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;ref&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; DefWndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;ref&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Message m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Result &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CallWindowProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;oldWndFunc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;HWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;WParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; m&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;LParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr WndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;IntPtr hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr wParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr lParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        Message msg &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Message&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Create&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;hWnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; wParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; lParam&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        WndProc&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;ref&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; msg&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Result&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108920218559780360?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108920218559780360/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108920218559780360' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108920218559780360'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108920218559780360'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/another-bug-another-workaround.html' title='Another bug, another workaround...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108877393259793553</id><published>2004-07-02T10:12:00.000-03:00</published><updated>2004-07-02T10:15:38.710-03:00</updated><title type='text'>Yet another bug on the .NET framework</title><content type='html'>I hit another bug on the .NET framework. No, this time the bug is not a &lt;a href="http://dturini.blogspot.com/2004/06/on-past-few-days-im-dealing-with-some.html"&gt;leak&lt;/a&gt; like the other &lt;a href="http://dturini.blogspot.com/2004/06/on-past-few-days-im-dealing-with-some.html"&gt;two&lt;/a&gt; &lt;a href="http://dturini.blogspot.com/2004/06/leaks-leaks-everywhere.html"&gt;times&lt;/a&gt;.&lt;br /&gt;I have this application that is starting to work, and it's starting to be a cool visual credit policies MDI editor. Now that the grunt work is done, I started to make the application visually appealing, and I started adding some icons to the toolbars. Everything was ok, until I added a toolbar and an ImageList to the main MDI form. Suddenly, every image on every toolbar on the application disappeared!&lt;br /&gt;What amazed me more was that at design time everything was ok. After a bit try this, disable that, I disabled the following line on my Main():&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#808080"&gt;///&lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#808080"&gt;&amp;ltsummary&amp;gt&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#808080"&gt;///&lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt; The main entry point for the application.&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#808080"&gt;///&lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#808080"&gt;&amp;lt/summary&amp;gt&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;STAThread&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Main&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#008000"&gt;// Application.EnableVisualStyles(); &amp;lt-- Removing this line "solved" the problem&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    Application&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Run&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Principal&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;Now I had something to search and after a bit of Google I found &lt;a href="http://www.codeproject.com/buglist/EnableVisualStylesBug.asp"&gt;this article&lt;/a&gt;. Although there are some failure reports on the posts below, Don is right: simply adding an Application.DoEvents worked like a charm!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108877393259793553?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108877393259793553/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108877393259793553' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108877393259793553'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108877393259793553'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/yet-another-bug-on-net-framework.html' title='Yet another bug on the .NET framework'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108876513182233366</id><published>2004-07-02T07:45:00.000-03:00</published><updated>2004-07-02T07:45:31.826-03:00</updated><title type='text'>Marc did it again!</title><content type='html'>&lt;a href="http://www.codeproject.com/script/profile/whos_who.asp?vt=arts&amp;id=36803"&gt;Marc Clifton&lt;/a&gt;, the &lt;a href="http://www.codeproject.com/script/articles/list_articles.asp?userid=36803"&gt;article writing machine&lt;/a&gt;, and &lt;a href="http://www.myxaml.com/"&gt;MyXaml&lt;/a&gt; &lt;a href="http://myxaml.com/marcclifton/"&gt;author&lt;/a&gt; did it again! Worried about &lt;a href="http://www.codeproject.com/"&gt;CodeProject&lt;/a&gt;'s increasing noise level, he and Anders Molin branched another Windows development site, &lt;a href="http://realdevs.net/"&gt;RealDevs.net&lt;/a&gt;. Speaking with some fellow programmers, some became worried about branching a site, which could split the development community. I don't think so: CodeProject was a branch from Codeguru, and look at the size it became, and CodeGuru still exists.&lt;br /&gt;What I love about the way Marc and Anders are doing their site is: high quality articles, use of modern tools (as of today, DNN, DotNetNuke), and openness. Modern tools are a must, IMO, because they'll be able to concentrate on what the users want, not on how to do it. Can you really understand why Codeproject still runs in traditional ASP? And Chris still has performance and scalability problems, even on cluster!&lt;br /&gt;&lt;a href="http://realdevs.net/Default.aspx?tabid=81&amp;mid=453&amp;ctl=ViewEntry&amp;EntryID=5"&gt;Openness&lt;/a&gt; is also very powerful: instead of hiding your problems, tell them to the world, after all we are programmers, and maybe we can help! If not help, we can maybe learn, hehehe.&lt;br /&gt;Quote of the day:&lt;br /&gt;&lt;blockquote&gt;&lt;i&gt;We both believe that there are no reasons for keeping a secret about what platform we use and what problems we have, so we will pretty much post all of it here ;)&lt;br /&gt;- Anders&lt;/i&gt;&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Good luck, guys!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108876513182233366?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108876513182233366/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108876513182233366' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108876513182233366'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108876513182233366'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/marc-did-it-again.html' title='Marc did it again!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108876391852943369</id><published>2004-07-02T07:25:00.000-03:00</published><updated>2004-07-02T07:25:18.533-03:00</updated><title type='text'>IDisposable Article Series - What's IDisposable?</title><content type='html'>IDisposable is, at the same time, one of the most simple and most important .NET interfaces. It consists of a single method, Dispose, with no parameters and returning nothing. It's declared by the .NET framework as follows:&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;namespace&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; System&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;interface&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IDisposable&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Dispose&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;The goal behind IDisposable is simple: to clear any unmanaged resources allocated by a class. And what are "unmanaged resources"? First, you need to understand what are "managed resources": memory. But not any memory: only memory that the .NET framework explicitly allocated.&lt;br /&gt;You probably know that the .NET framework provides you with a garbage collector (GC). While a standard technical term, I don't agree with this, I think it's not a precise term, at least in the .NET environment: there's no real "garbage collector" in .NET. What really exists is a memory recycler. Basically, you are not in control of memory deallocation and the environment takes care of this for you. Think of this as a "controlled memory leak". Your code will only ask for the GC to allocate memory and keep track of its uses, and when something triggers it (probably a combination of idle time, memory pressure and even maybe the size of your L2 cache), the GC comes in and releases all the unused memory. While this, most of the time, achieves high levels of performance and reliability, also has some very bad consequences:&lt;br /&gt;&lt;ul&gt;&lt;br /&gt;&lt;li&gt;There's no way to predict when the GC comes in;&lt;br /&gt;&lt;li&gt;There's no simple way to have a predictable destructor on your class, like in C++ and even VB 6.0.&lt;br /&gt;&lt;/ul&gt;&lt;br /&gt;If there are no predictable destructors in the .NET environment, how can API wrapper classes (e.g) Control, Bitmap, Socket or FileStream, which hold a handle to physical, costly or scarce resources, be able to automatically close handles or execute clean up code? They can't: at least, in a predictable way. So, IDisposable comes to scene, and you, the class user, are responsible for the lifetime management.&lt;br /&gt;&lt;br /&gt;Next article part:&lt;br /&gt;What are the responsibilities of the IDisposable for the class user?&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108876391852943369?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108876391852943369/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108876391852943369' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108876391852943369'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108876391852943369'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/07/idisposable-article-series-whats.html' title='IDisposable Article Series - What&apos;s IDisposable?'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108807690949838783</id><published>2004-06-24T08:35:00.000-03:00</published><updated>2004-06-24T10:35:56.166-03:00</updated><title type='text'>All you ever wanted to know about the IDisposable and was ashamed to ask</title><content type='html'>I have some coworkers who are new to the .NET world, and still need to be introduced to the platform best practices. One of the key knowledge that every .NET programmer should have is the IDisposable interface; when to implement it and when to call it. What happens when you fail to do that is one of the points of this article, but for now let's just say that it can lead to difficult to track software bugs, memory and resource leaks.&lt;br /&gt;Before writing this I researched the Web a lot to find a single place that I could point my colleagues in order to learn about IDisposable, but I could not find an article that covers it both fully and deeply, so I decided to start writing.&lt;br /&gt;As I don't have much free time for now, I will post this on my blog one chapter at a time, probably one topic each day, and when it is finished, I'll post this on sites like &lt;a href="http://www.codeproject.com/"&gt;Code Project&lt;/a&gt; as a finished (huge) article.&lt;br /&gt;&lt;br /&gt;The topics I intend to cover are (note that this is my initial planned outline, may it changes a little while I write, but you can consider this as a bare minimum):&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;The beginning&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;What's IDisposable?&lt;br /&gt;What are the responsibilities of the IDisposable for the class user?&lt;br /&gt;What happens if I don't call Dispose? Why is IDisposable needed?&lt;br /&gt;Isn't .NET garbage-collected?&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Calling Dispose&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;What happens if I call Dispose twice?&lt;br /&gt;What happens if I use an object that had Dispose called?&lt;br /&gt;Where's the correct place to call Dispose?&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Implementing IDisposable&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;What is the correct way of implementing IDisposable?&lt;br /&gt;Don't forget to throw ObjectDisposedException.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;C# Support to IDisposable:&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;What about C# destructors?&lt;br /&gt;The "using" statement.&lt;br /&gt;The "foreach" statement.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Design implications:&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;Close or Dispose? Why do both exist?&lt;br /&gt;Why did someone choose a private implementation of IDisposable?&lt;br /&gt;Implications for library writers&lt;br /&gt;Should I dispose a whole hierarchy of IDisposable instances or only the root?&lt;br /&gt;Mis"using" C# support for IDisposable.&lt;br /&gt;&lt;br /&gt;&lt;i&gt;&lt;b&gt;Useful links for more information&lt;/b&gt;&lt;/i&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108807690949838783?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108807690949838783/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108807690949838783' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108807690949838783'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108807690949838783'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/all-you-ever-wanted-to-know-about.html' title='All you ever wanted to know about the IDisposable and was ashamed to ask'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108757815485921927</id><published>2004-06-18T14:02:00.000-03:00</published><updated>2004-06-18T15:06:47.436-03:00</updated><title type='text'>Leaks, leaks, everywhere...</title><content type='html'>I think I'm becoming an authority on finding .NET leaks: I just found a handle leak on the EventLog class.&lt;br /&gt;The problem, this time is with the static method (decompiled with &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Lutz Roeder's&lt;/a&gt; .NET Reflector):&lt;br /&gt; &lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WriteEntry&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; source&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; message&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; EventLogEntryType type&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; eventID&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;&lt;br /&gt;                              &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;short&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; category&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;byte&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; rawData&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    EventLog log1 &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; EventLog&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    log1&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Source &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; source&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    log1&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;WriteEntry&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;message&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; type&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; eventID&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; category&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; rawData&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;Noticed? EventLog implements IDisposable and the code should be this:&lt;br /&gt;&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;void&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WriteEntry&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; source&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; message&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; EventLogEntryType type&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; eventID&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;br /&gt;                             &lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;short&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; category&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;byte&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; rawData&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;EventLog log1 &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; EventLog&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        log1&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Source &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; source&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        log1&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;WriteEntry&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;message&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; type&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; eventID&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; category&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; rawData&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;So, the lesson is: if you care about not leaking handles (e.g., in server applications, where a few handles per processing unit can shut down a whole service), don't use LogEvent static methods. Create an instance and call its methods, and dispose it yourself.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108757815485921927?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108757815485921927/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108757815485921927' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108757815485921927'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108757815485921927'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/leaks-leaks-everywhere.html' title='Leaks, leaks, everywhere...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108756796526410850</id><published>2004-06-18T11:12:00.000-03:00</published><updated>2004-06-18T15:09:44.066-03:00</updated><title type='text'>Eric is right!</title><content type='html'>This post isn't about programming, but is about making money programming. &lt;a href="http://software.ericsink.com/"&gt;Eric&lt;/a&gt; is talking about the 22 Immutable Laws of Marketing, and today he posted &lt;a href="http://software.ericsink.com/item_10188.html"&gt;Law #13: The Law of Sacrifice&lt;/a&gt;. Nothing could be more appropriate to me today.&lt;br /&gt;I had this insanely good project, and that would mean a very nice amount of money. Today, I had to say "no" to it because the deadlines are too risky. More than this, it would mean a stop on the development a lot of nice features on Crivo that would fit so well to so many customers, that, in the long term would mean that we're hurting Crivo's feature.&lt;br /&gt;But it's hard to say "no" and it's hard to keep this decision after saying that...&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108756796526410850?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108756796526410850/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108756796526410850' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108756796526410850'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108756796526410850'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/erik-is-right.html' title='Eric is right!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108741681700661311</id><published>2004-06-16T17:13:00.000-03:00</published><updated>2004-06-16T17:13:37.013-03:00</updated><title type='text'>Deriving from Panel woes</title><content type='html'>If you're deriving from Panel, set AutoScroll to true and set AutoScrollMinSize to some big numbers, you get a Panel with ScrollBars, right?&lt;br /&gt;Right: everything works, but the OnMouseWheel event doesn't happen, and the mouse wheel don't work. After googling a lot, I happened to discover that the mouse wheel is only sent to controls when they have the focus (doh! it should be obvious!).&lt;br /&gt;So, correcting this is a simple matter of SetStyle(ControlStyles.Selectable, true) and then, at some place (probably on OnMouseDown or OnMouseEnter), you call Focus().&lt;br /&gt;Voil&amp;aacute;! Instant mousewheel support on your Panel!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108741681700661311?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108741681700661311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108741681700661311' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108741681700661311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108741681700661311'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/deriving-from-panel-woes.html' title='Deriving from Panel woes'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108738875979339679</id><published>2004-06-16T09:25:00.000-03:00</published><updated>2004-06-16T09:25:59.836-03:00</updated><title type='text'>I'm new to this blog thing...</title><content type='html'>And I'm yet discovering new things. By default, Blogger has the title field disabled, and the blog started to get confusing. I've changed the setting, but if you subscribed to my Atom feed, you probably noticed that the older posts became duplicated, because Blogger was sending a bogus title for previous posts...&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108738875979339679?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108738875979339679/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108738875979339679' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108738875979339679'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108738875979339679'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/im-new-to-this-blog-thing.html' title='I&apos;m new to this blog thing...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108733007828822973</id><published>2004-06-15T17:07:00.001-03:00</published><updated>2004-06-16T09:17:48.516-03:00</updated><title type='text'>More on Try/Finally.</title><content type='html'>Along the lines of my previous post, this month's MSDN Magazine &lt;a href="http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx"&gt;has an interesting article&lt;/a&gt; about unexpected errors in managed applications. On the "Some Best Practices" topic, Jason puts some quite strong arguments that go exactly along the lines of my post.&lt;br /&gt;Some highlights:&lt;br /&gt;&lt;br /&gt;&lt;i&gt;    * Don't catch or throw base exception types&lt;br /&gt;    * Use finally blocks liberally&lt;br /&gt;&lt;/i&gt;&lt;br /&gt;&lt;b&gt;(...)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;&lt;i&gt;Now let's look at the guideline surrounding finally blocks. In general, well-written managed code contains more try/finally constructs than it does try/catch constructs. The reason for this is that finally blocks guarantee the ability to perform method-level clean-up operations in both exceptional and non-exceptional executions. Many methods include code that qualifies as "clean-up operations." This includes the closing of files and other resources that were opened in the method, unlocking synchronization locks that were taken during the method, and so forth. Meanwhile, if you follow the first guideline-only catching expected exceptions-the number of methods that actually catch any exceptions at all is reduced in the end.&lt;/i&gt;&lt;br /&gt;&lt;br /&gt;It's nice to see that I'm not alone thinking this way!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108733007828822973?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108733007828822973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108733007828822973' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108733007828822973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108733007828822973'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/more-on-tryfinally.html' title='More on Try/Finally.'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108723363178731313</id><published>2004-06-14T14:20:00.000-03:00</published><updated>2004-06-16T09:17:40.280-03:00</updated><title type='text'>Try/Finally for cleaner cleanup.</title><content type='html'>One thing that people often overlook is how a try/finally block can make your code both more readable and more robust. It's a great tool for cleanup code. You can see me using it on the GetErrorMessage on my WinHTTPException class. If you look carefully, you'll see that I close the handle &lt;b&gt;after&lt;/b&gt; the return statement.&lt;br /&gt;As a sample, suppose you need to read some temporary information from a file and return it as a string. No matter what happens, you need to delete this file, because it's temporary. This kind of return &amp; cleanup begs for a try/finally block. &lt;br /&gt;&lt;br /&gt;Let's see the simplest possible code without using try/finally:&lt;br /&gt;&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        fileContents &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;This code also has a problem when an exception is thrown on, e.g, the ReadToEnd method. So, I've actually saw some people trying to solve it coding as this:&lt;br /&gt;&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            fileContents &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; fileContents&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;catch&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Exception&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;throw&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;The code is becoming complex and it's starting to duplicate code.&lt;br /&gt;&lt;br /&gt;Now, see how much cleaner and robust is the try/finally solution:&lt;br /&gt;&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; ReadTempFile&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;StreamReader sr &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StreamReader&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ReadToEnd&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;finally&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        File&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Delete&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FileName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;br /&gt;Where did the fileContents variable go? It's not necessary anymore, because we can return the contents and the cleanup code executes after the return point. This is one of the advantages of having code that can run &lt;b&gt;after&lt;/b&gt; the function returns: you can clean resources that may be needed for the return statement.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108723363178731313?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108723363178731313/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108723363178731313' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108723363178731313'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108723363178731313'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/tryfinally-for-cleaner-cleanup.html' title='Try/Finally for cleaner cleanup.'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108697852261773170</id><published>2004-06-11T15:28:00.001-03:00</published><updated>2004-06-16T09:17:13.976-03:00</updated><title type='text'>Resharper</title><content type='html'>I just can't avoid mentioning &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt;. What a great tool!&lt;br /&gt;If you don't know it yet, JetBrains is providing an &lt;a href="http://www.jetbrains.net/resharper"&gt;Early Access Program&lt;/a&gt; for free.&lt;br /&gt;It's a refactoring tool for C# and VS.NET, which basically makes your IDE as smart as IntelliJ.&lt;br /&gt;Try it and you won't regret!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108697852261773170?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108697852261773170/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108697852261773170' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108697852261773170'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108697852261773170'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/i-just-cant-avoid-mentioning-resharper.html' title='Resharper'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108680857527782686</id><published>2004-06-09T16:16:00.000-03:00</published><updated>2004-06-16T09:16:51.213-03:00</updated><title type='text'>Case insensitive String functions</title><content type='html'>The more I use .NET, the more I become astonished about what I still don't know. No, I'm not talking about some highly-advanced features: I'm talking about simple things, as string methods.&lt;br /&gt;Sometimes you may need to do a case-insensitive IndexOf, or a case-insensitive StartsWith. Most people would call ToLower or ToUpper. This has two problems:&lt;br /&gt;1.	This is not the same thing than a case-insensitive search on some cultures. Second&lt;br /&gt;2.	This is slow, and creates two more objects to be collected. If done on a loop, this can create a lot of unnecessary overhead.&lt;br /&gt;&lt;br /&gt;The solution most people (me included) do is creating their own case-insensitive IndexOf or StartsWith.&lt;br /&gt;Until I found the CompareInfo class. You can use it through CultureInfo.CurrentCulture.CompareInfo and call, e.g.:&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;CultureInfo.CurrentUICulture.CompareInfo.IndexOf(text, substring, CompareOptions.IgnoreCase)&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;Cool, huh?&lt;br /&gt;It's very fast and doesn't add overhead to the GC.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108680857527782686?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108680857527782686/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108680857527782686' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108680857527782686'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108680857527782686'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/case-insensitive-string-functions.html' title='Case insensitive String functions'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108678873042761208</id><published>2004-06-09T10:45:00.000-03:00</published><updated>2004-06-16T09:16:30.600-03:00</updated><title type='text'>Free from the pad!</title><content type='html'>Oh, the joy!&lt;br /&gt;Input and output devices should be where you spend most of your money when building a new computer: they increase productivity like anything else, and their value have a low depreciation through time.&lt;br /&gt;At my office, I use two 17" monitors, a cool MS keyboard with lots of cool features. I also work on a big desk, with lots of space. But I never thought of upgrading my old, trusty Logitech mouse with a wheel: it worked, and I thought it was as good as an optical mouse, and it was only that cool red led light that attracted people. I couldn't be farther from the truth. Yesterday, I used one for a while on a coworker's machine, and when I got back to my old mouse, I couldn't like it anymore. Just the absence of the mouse pad and the freedom to move it on is worth the upgrade. Now, I bought this MS basic optical mouse: it is beautiful, cheap, and looks distinct, seems reliable and easy to install; I plugged right into one of the keyboard USB ports and it started working.&lt;br /&gt;&lt;br /&gt;Run, my little mouse, run free from the pad!&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108678873042761208?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108678873042761208/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108678873042761208' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108678873042761208'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108678873042761208'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/oh-joy-input-and-output-devices-should.html' title='Free from the pad!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108670980943385211</id><published>2004-06-08T12:50:00.000-03:00</published><updated>2004-06-16T09:15:48.546-03:00</updated><title type='text'>Don Knuth: Musings and more</title><content type='html'>I just found a great page: &lt;a href="http://scpd.stanford.edu/knuth/"&gt;Knuth: Musings and more&lt;/a&gt;. A series of videos featuring the great Don Knuth. I didn't watch them yet, but I plan doing it on the weekend.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108670980943385211?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108670980943385211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108670980943385211' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108670980943385211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108670980943385211'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/i-just-found-great-page-knuth-musings.html' title='Don Knuth: Musings and more'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108663937092655901</id><published>2004-06-07T17:16:00.000-03:00</published><updated>2004-06-16T09:15:06.930-03:00</updated><title type='text'>Visual Studio Debugger Breakpoint Helper</title><content type='html'>Great tool!&lt;br /&gt;&lt;a href="http://www.codeproject.com/script/profile/whos_who.asp?id=3658"&gt;Kant&lt;/a&gt; &lt;a href="http://www.codeproject.com/lounge.asp?msg=843794#xx843794xx"&gt;mentioned&lt;/a&gt;, on CP lounge, a great tool for troubleshooting  breakpoints that don't work.&lt;br /&gt;&lt;a href="http://www.controlav.com/bphelper/start.asp"&gt;Visual Studio Debugger Breakpoint Helper&lt;/a&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108663937092655901?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108663937092655901/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108663937092655901' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108663937092655901'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108663937092655901'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/great-tool-kant-mentioned-on-cp-lounge.html' title='Visual Studio Debugger Breakpoint Helper'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108663586278328727</id><published>2004-06-07T16:17:00.000-03:00</published><updated>2004-06-16T09:14:34.750-03:00</updated><title type='text'>Win32Exceptions capable of dealing with module error messages</title><content type='html'>For those who may be, like me, in need of an exception that properly deals with Win32 error codes (obtained from GetLastError()) that can come from the system or an specific module, the code below does the trick.&lt;br /&gt;You can change the name "WINHTTP" (it's what I'm dealing right now) for any DLL name you have and go for it!&lt;br /&gt;&lt;br /&gt;&lt;FONT FACE="Courier New"&gt;&lt;PRE&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; System&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; System&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Text&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; System&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Runtime&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;InteropServices&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;using&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; System&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ComponentModel&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#0000FF"&gt;namespace&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WinHTTP&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;class&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WinHTTPException &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;:&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Win32Exception&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"kernel32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Auto&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; SetLastError&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;true&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FormatMessage&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; dwFlags&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; HandleRef lpSource&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; dwMessageId&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; dwLanguageId&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StringBuilder lpBuffer&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; nSize&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr arguments&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"kernel32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Auto&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; SetLastError&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;true&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr GetModuleHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; lpModuleName&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;[&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;DllImport&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"kernel32.dll"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;CharSet&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Auto&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;]&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;static&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;extern&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;bool&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; CloseHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;HandleRef handle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FORMAT_MESSAGE_FROM_HMODULE &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000800&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FORMAT_MESSAGE_ALLOCATE_BUFFER &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000100&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FORMAT_MESSAGE_IGNORE_INSERTS &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00000200&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;const&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FORMAT_MESSAGE_FROM_SYSTEM &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0x00001000&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WinHTTPException&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;:&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;base&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Marshal&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;GetLastWin32Error&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; WinHTTPException&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; NativeErrorCode&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;:&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;base&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;NativeErrorCode&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;private&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GetErrorMessage&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            IntPtr hModule &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;try&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                hModule &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GetModuleHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"WINHTTP"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; error &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; NativeErrorCode&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;if&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;hModule &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Unknown error "&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; error&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ToString&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"X"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                StringBuilder sb &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; StringBuilder&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;1024&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;int&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; res &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FormatMessage&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;FORMAT_MESSAGE_FROM_SYSTEM &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;|&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; FORMAT_MESSAGE_FROM_HMODULE&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; HandleRef&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;this&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; hModule&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;error&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sb&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;uint&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;sb&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Capacity&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;if&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;res &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; 0&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"Unknown error "&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;+&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; error&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ToString&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#800080"&gt;"X"&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;else&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                    &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; sb&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;ToString&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;0&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; res&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;finally&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;if&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;hModule &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;!&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;=&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; IntPtr&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;.&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;Zero&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                    CloseHandle&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;new&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; HandleRef&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;this&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;,&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; hModule&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;public&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;override&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;string&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; Message&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;get&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;{&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;                &lt;/FONT&gt;&lt;FONT COLOR="#0000FF"&gt;return&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt; GetErrorMessage&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;(&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;)&lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;            &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;        &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;    &lt;/FONT&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;}&lt;/FONT&gt;&lt;br /&gt;&lt;FONT COLOR="#000000"&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;br /&gt;&lt;/FONT&gt;&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108663586278328727?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108663586278328727/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108663586278328727' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108663586278328727'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108663586278328727'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/for-those-who-may-be-like-me-in-need.html' title='Win32Exceptions capable of dealing with module error messages'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108645179411990903</id><published>2004-06-05T13:09:00.000-03:00</published><updated>2004-06-16T09:13:42.573-03:00</updated><title type='text'>Solved the Win32Exception mistery...</title><content type='html'>Great! I wrote my own exception, similar to Win32Exception, and now it's working. I'm calling FormatMessage with FORMAT_MESSAGE_FROM_HMODULE | FORMAT_MESSAGE_FROM_SYSTEM and the proper messages are being retrieved.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108645179411990903?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108645179411990903/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108645179411990903' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108645179411990903'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108645179411990903'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/great-i-wrote-my-own-exception-similar.html' title='Solved the Win32Exception mistery...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108643957694924718</id><published>2004-06-05T09:46:00.000-03:00</published><updated>2004-06-16T09:13:09.916-03:00</updated><title type='text'>My managed WinHTTP wrapper starts to work...</title><content type='html'>My WinHTTP wrapper is starting to work. I even made a nicer OOP model around WinHTTP, with a Session, a Connection, a Request, a Response (WinHTTP doesn't have a Response handle, everything belongs to the Request handle), and a ResponseStream that can be used to read the page.&lt;br /&gt;The exceptions aren't still being able to get the proper Win32 messages, I can't understand why, as I'm using System.ComponentModel.Win32Exception and SetLastError = True on Interop.&lt;br /&gt;Now, I just need to add support to HTTP status codes, headers and I'm done.&lt;br /&gt;This really begs for an article, I wish I had a bit more free time (notice, it's Saturday and I'm working...)&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108643957694924718?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108643957694924718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108643957694924718' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108643957694924718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108643957694924718'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/woot-my-winhttp-wrapper-is-starting-to.html' title='My managed WinHTTP wrapper starts to work...'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108635533693077868</id><published>2004-06-04T10:22:00.000-03:00</published><updated>2004-06-16T09:12:23.100-03:00</updated><title type='text'>P/Invoke to the rescue</title><content type='html'>I just realized that I won't need to download the Platform SDK on all of our machines. I'll write a WinHTTP wrapper in C# (I sense a new CP article comming), so there'll be no need for the updated SDK on the machines.&lt;br /&gt;Sure, I'll send it to &lt;a href="http://www.pinvoke.net/"&gt;PInvoke.NET&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108635533693077868?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108635533693077868/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108635533693077868' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108635533693077868'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108635533693077868'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/i-just-realized-that-i-wont-need-to.html' title='P/Invoke to the rescue'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108634521892147690</id><published>2004-06-04T07:33:00.000-03:00</published><updated>2004-06-16T09:11:53.946-03:00</updated><title type='text'>I quit!</title><content type='html'>Unfortunately, I've tried everything and it wasn't enough. The leaks may seem harmless on a desktop application, which can leak a few handles and then wait for the garbage collector to appear, but in a server application it's simply a killer. On a 4-way SMP, there may be up to 100 simultaneous request running (each request takes an average of 5 seconds to complete), and if each of them leak 30 handles, I'm leaking 600 handles/second. The GC simply isn't smart enough to clean all of them and the number never gets down.&lt;br /&gt;Since Crivo only is supported on Windows 2000, XP and 2003 with the last Service Pack applied, an alternative way is by using WinHTTP. No code in Crivo calls directly the .NET HTTP libraries, we provide a smart facade (similar to System.Net.WebClient, but smarter), so it's "just" a matter of rewriting our HTTP library to use WinHTTP.&lt;br /&gt;BTW, I just discovered that WinHTTP is not included on the SDK that came with VS.NET 2003, and since it's now part of the OS (a good thing, IMO), it's not available for separate download anymore. To get it now, we need to run Platform SDK update on all development machines and on the build machine (~250 MB). :sigh:&lt;br /&gt;I think I'll start by writing some C++ wrapper classes. Those who worked with me in the past know that I've always been a fan of &lt;a href="http://blogs.msdn.com/ericgu/archive/2004/04/21/117958.aspx"&gt;RAII&lt;/a&gt;.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108634521892147690?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108634521892147690/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108634521892147690' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108634521892147690'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108634521892147690'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/i-quit-unfortunately-ive-tried.html' title='I quit!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108627144480121570</id><published>2004-06-03T11:04:00.000-03:00</published><updated>2004-06-16T09:11:22.766-03:00</updated><title type='text'>Damn! Handle leaks on the CLR!</title><content type='html'>On the past few days, I'm dealing with some hard to find resource leaks. We seem to be pushing some areas CLR to their limit. You may say, "hey, how can you get resource leaks in a garbage collected environment"?.&lt;br /&gt;Well, the simple code below will leak lots of handles.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;div&gt;&lt;span style="color: #000000; "&gt;        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;private&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;void&lt;/span&gt;&lt;span style="color: #000000; "&gt; MakeARequest()&lt;br /&gt;        {&lt;br /&gt;            HttpWebRequest wr &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; (HttpWebRequest)WebRequest.Create(&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;http://www.microsoft.com/&lt;/span&gt;&lt;span style="color: #000000; "&gt;&amp;quot;&lt;/span&gt;&lt;span style="color: #000000; "&gt;);&lt;br /&gt;            wr.Proxy &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; WebProxy.GetDefaultProxy();&lt;br /&gt;            wr.Proxy.Credentials &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; CredentialCache.DefaultCredentials;&lt;br /&gt;            &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; (HttpWebResponse wrp &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; (HttpWebResponse)wr.GetResponse())&lt;br /&gt;            {&lt;br /&gt;                &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; (Stream s &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; wrp.GetResponseStream())&lt;br /&gt;                {&lt;br /&gt;                    &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;using&lt;/span&gt;&lt;span style="color: #000000; "&gt; (StreamReader sr &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;new&lt;/span&gt;&lt;span style="color: #000000; "&gt; StreamReader(s))&lt;br /&gt;                    {&lt;br /&gt;                        &lt;/span&gt;&lt;span style="color: #0000FF; "&gt;string&lt;/span&gt;&lt;span style="color: #000000; "&gt; st &lt;/span&gt;&lt;span style="color: #000000; "&gt;=&lt;/span&gt;&lt;span style="color: #000000; "&gt; sr.ReadToEnd();&lt;br /&gt;                        sr.Close();&lt;br /&gt;                        s.Close();&lt;br /&gt;                    }&lt;br /&gt;                }&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Did you see it? It isn't missing a single Close() or Dispose() call, and yet leaks lots of handles. The biggest the page, the more handles it leaks.&lt;br /&gt;I've been using an evaluation version (10 days remaining...) of &lt;a href="http://www.scitech.se/memprofiler/"&gt;the great SciTech's .NET memory profiler&lt;/a&gt; and noticed that the CLR is forgetting to dispose some (a lot!) ManualResetEvent, Sockets, and some internal Streams and Readers.&lt;br /&gt;After a while, I found that the culprit are the synchronous HttpWeb(Request, Response) methods, and, by calling the assynchronous versions, I was able to reduce it a lot. Even the returned stream, System.Net.ConnectStream have these problems.&lt;br /&gt;The only problem is when the request throws an Exception, it still leaks lots of handles, and, by now, it seems that I can do nothing about it...&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108627144480121570?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108627144480121570/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108627144480121570' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108627144480121570'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108627144480121570'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/on-past-few-days-im-dealing-with-some.html' title='Damn! Handle leaks on the CLR!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5389857.post-108626505322195258</id><published>2004-06-03T08:58:00.000-03:00</published><updated>2004-06-16T09:09:54.853-03:00</updated><title type='text'>My first post!</title><content type='html'>On this blog, I intend to start sharing some knowledge and experiences on .NET development in general.&lt;br /&gt;I'd like to introduce myself, if you still don't know me from &lt;a href="http://www.codeproject.com/"&gt;The CodeProject&lt;/a&gt;. If this is the case, maybe you could be interested in some of &lt;a href="http://www.codeproject.com/script/articles/list_articles.asp?userid=18901"&gt;my articles&lt;/a&gt;.&lt;br /&gt;I'm the technical architect of &lt;a href="http://www.crivo.com.br/"&gt;Crivo&lt;/a&gt;. Crivo is an automated credit and risk assessment system, used by several large companies in Brazil. We combine some AI techniques (perceptrons and an expert rule inference engine) with a set of drivers which can obtain information in almost any information source. This set of drivers is one of our most powerful features, and we can deliver more than 27,000 variables coming from around 30 different sources to the assessment engine so it can take a decision.&lt;br /&gt;It's a huge .Net based system (around 1.3MLOC as of date), comprised of around 180 projects. And it's growing fast, as we have a very productive team. As I blog, I'll talk more about how we develop software.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5389857-108626505322195258?l=dturini.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://dturini.blogspot.com/feeds/108626505322195258/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=5389857&amp;postID=108626505322195258' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108626505322195258'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5389857/posts/default/108626505322195258'/><link rel='alternate' type='text/html' href='http://dturini.blogspot.com/2004/06/my-first-post-on-this-blog-i-intend-to.html' title='My first post!'/><author><name>Daniel</name><uri>http://www.blogger.com/profile/07861830925924901678</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
