Why Reship a Buggy API?

Version 1.0 of the .NET Framework introduced System.Drawing.Region‘s Union method, designed to union two regions or several other types into a region. A bug, first reported in 2001, caused unexpected behavior. The method’s output was determined as unreliable.

Version 1.1 went past and the bug was not fixed. Then version 2.0 went by and the bug was still left unfixed. I haven’t checked on version 3.0, but my money’s on it still not being fixed.

The situation we have today is one of an API that was released 6 years ago and still has a known, crippling bug making it unusable, yet there is absolutely no documentation (no, being able to find some MVPs’ user groups posts about the bug is not documentation) and the method was never removed or even made obsolete!

Now the post’s question is raised – Why would you re-ship an API known to be buggy beyond any workaround, version after version after version for more than half a decade? There’s no backwards compatibility needed here, since no one would use this feature once they realized it would fail them. The least you could do is put a big, red, blinking warning in the documentation stating that this API has never worked and still does not work to date.

So a warning to all who think of trying: Do not use Region’s Union method!


7 thoughts on “Why Reship a Buggy API?

  1. Have you tried testing the GDI+ native functions these call to see if those are buggy too? Because that’s all Region.Union is: a wrapper around a set of CombineRegion* functions in GDIPLUS.DLL.
    They can’t fix something in the framework that’s broken in the native API’s it’s wrapping.

  2. It just gives out the wrong results. I tried using it to plot regions on a picture, but every once in a while, and sometimes a few times in a row, the resulting region would be distorted.

  3. Joe –
    I don’t mind the bug being there (well, I actually do mind it, but that’s not the point of the post), but what I do mind is the public API that exposes it and has been for the past 6 years…
    The fact that it’s a public API wrapping another public API is even more aggravating, since there are now two points of failure instead of one – for those calling the wrapper and for those calling GDI+ directly…

  4. There are a slew of nasty bugs in the System.Drawing namespace. I’ve personally encountered one in the Pen class (see http://www.dotnet247.com/247reference/msgs/42/212045.aspx, although that’s not my posting).
    It disappoints me that Microsoft puts so much work into making the .NET Framework a joy to use, and then neglects to fix small but very obvious bugs such as these. Honestly, how much effort is it to ship fixed GDI DLLs with the Framework installer?

  5. I’ve experienced similar troubles while trying to use the System.Drawing.Region’s Union method. I must say I’m also quite disappointed to realize that Microsoft doesn’t mind keeping a bug in such an elementary functionality of the Region class. Let me add that I found very little reference to this problem on the internet.
    For those who need more details on the bug, I can say that basically, the region resulting from an Union may be truncated of some of its rectangular parts (not necessarily a whole rectangle that has previously been added). The error seems to occur when at least three rectangles have parts that share the same x or the same y. The order in which the rectangles are added to the region also has an influence on the outcome (since adding a rectangle to a region that already contains this rectangle has seems to have no effect).
    I came up with a small patch that consists in testing if the region has properly included the invalidation rectangle. Basically, after using the Union method, I create a copy of the resulting region, complement it with the rectangle that has been added, and test if the complemented region is empty. If it’s not, it means the Union has failed; in which case I combine all the rectangles contained in the original region in a single big rectangle (using the GetBounds method), and add the rectangle to invalidate to it. The region now contains two rectangles.
    The problem with this patch is the significant impact it has on performance. Profiling this part of the code shows that a call to the IsEmpty method of the Region class strangely takes a lot of time (also, a strange thing is that it takes a System.Drawing.Graphics in parameter).
    If anyone comes up with a better alternative, I’m interested!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s