[Mono-winforms-list] "System.NotImplementedException: Bitmap.InitFromStream (win32)"

Ricardo Stuven Ricardo Stuven <rstuven@gmail.com>
Tue, 26 Apr 2005 12:03:22 -0400


Hi,

I'm trying Mono 1.1.6 in Windows XP. This simple line:
        MessageBox.Show(text);
...raises the following exception:
________________________________________________________

        Unhandled Exception: System.TypeInitializationException: An excepti=
on
was thrown
         by the type initializer for MessageBoxForm --->
System.Reflection.TargetInvocat
        ionException: Exception has been thrown by the target of an
invocation. ---> Sys
        tem.NotImplementedException: Bitmap.InitFromStream (win32)

        in <0x00103> System.Drawing.Image:InitFromStream
(System.IO.Stream stream)
        [...]
        in <0x0052b> System.Resources.ResourceReader:ResourceValue (Int32 i=
ndex)
        [...]
        in <0x00010> System.Resources.ResourceManager:GetObject
(System.String name)
        in <0x00017> System.Windows.Forms.Locale:GetResource
(System.String name)
        in <0x00012>
System.Windows.Forms.MessageBox+MessageBoxForm:.cctor ()--- End of
        inner exception stack trace ---
        in <0x00000> <unknown method>
        in <0x0002c> System.Windows.Forms.MessageBox:Show (System.String te=
xt)
        [...]
________________________________________________________

I digged a bit into the source code of Mono and found the following clues:

*)  System.Drawing\Image.cs has an explanation:

        // this is MS-land
        // FIXME
        // We can't call the native gdip functions here, because they expec=
t
        // a COM IStream interface.  So, a hack is to create a tmp file, re=
ad
        // the stream, and then load from the tmp file.
        // This is an ugly hack.
        throw new NotImplementedException ("Bitmap.InitFromStream (win32)")=
;

*) MessageBoxForm tries to get reources in this way:
internal static Image   info_icon       =3D
(Image)Locale.GetResource("mbox_info.png");

*) There is a System.Runtime.InteropServices.ComTypes\IStream.cs
implemented only "if NET_2_0".

I have two questions:

1) Is it feasible to resolve this issue using the above-mentioned
IStream, declaring something like:

        [DllImport("gdiplus.dll")]
        internal static extern Status GdipLoadImageFromStream ( IStream
stream, out IntPtr image );

...in System.Drawing.gdipFunctions.cs, and then using it in
Image:InitFromStream "MS-land" ?

2) Is it really necessary that MessageBox tried to load an image
resource when the call was just ".Show(text)" ? Maybe it's better to
load the resources in the "switch (icon)" part...

Hoping my comments be useful.
Regards,
Ricardo Stuven.