[Mono-dev] Portability: System.Drawing.Image vs GDIPlus.GdipLoadImageFromFile

Francis Fisher lists.ximian.com at terrorise.me.uk
Thu Aug 15 13:57:01 UTC 2013

I've encountered an issue in some software that calls 
System.Drawing.Image (), passing in a filename that is not portable 
which I've raised as bug #14002.

System.Drawing.Image () verifies the file's existence with File.Exists 
(which uses the Mono.IO portability framework), then passes the filename 
to GDIPlus.GdipLoadImageFromFile () which does not use the portability 
framework and fails to open the file.

To fix this, I either need to make GdipLoadImageFromFile use the same 
portability mechanism as has been built into Mono.IO, or 
System.Drawing.Image () needs to convert the filename it receives (if 
necessary) before passing it to GdipLoadImageFromFile ().

As I see it, the disadvantage of fixing GDIPlus is that as a separate 
library to Mono, it may require code duplication which might lead to 
divergent code bugs in the future. On the other hand, if its common 
practice for user software (and not just the class libraries) to call 
GDIPlus.GdipLoadImageFromFile, then it absolutely has to be fixed in the 
GDIPlus library - converting the filename within System.Drawing.Image 
would only solve a subset of the issue.

If user software never calls GDIPlus.GdipLoadImageFromFile directly, 
then it could be quite safe to fix it in System.Drawing.Image, which 
would mean that we don't have to duplicate code between mono and GDIPlus.

A 3rd option that would avoid duplicating code between GDIPlus and 
Mono.IO could be to have some kind of managed code wrapper to 
GdipLoadImageFromFile that calls a function in Mono.IO to find the 
correct filename, before passing the converted filename onwards. That 
would leave the portability code in one place, but still allow GDIPlus 
to take advantage of it.

Any thoughts about which route I should go down?

Frankie Fisher

More information about the Mono-devel-list mailing list