The Church of Using
One my latest project working for Citigroup, I've been working with an Open Source component named PdfSharp.This wonderful little component lets you create and modify Pdf documents and has the advantage of behaving much more like a .NET component than the popular ITextSharp, which is a port of a Java PDF library.One of the things I needed to do was put a GIF image into the bottom half of a PDF document.Simple enough using PdfSharp, just get a set of PdfDocument, XGraphic and XImage objects and do some math for the placement.All was happiness and light until we decided we needed to clean-up the created Pdf after we were done with it.Suddenly we would sometimes get Sharing Violations on deleting the file.But only sometimes.
Fortunately experience has taught me that "sometimes" errors can only be a few types of situations, and in this case one made the most sense ... Garbage Collection.I went pouring over every piece of code looking for where I missed an object that, I hoped, implemented IDisposable and sure enough discovered that PdfDocument, XGraphic and XImage all implemented IDisposable but did not have a public Dispose method.This is perfectly fine, but does make it harder to know when you should use IDisposable.
In the end, the error was of course mine.As such I have done 50 "Hail Using"s (in VB since they now support it) and lit a candle in rememberance of lost productivity.