Bug 17359 - Using an icon causes a null reference GDI+ error
Summary: Using an icon causes a null reference GDI+ error
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms (show other bugs)
Version: 2.10.x
Hardware: PC Linux
: Lowest normal
Target Milestone: Community
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-21 18:09 UTC by David Grayson
Modified: 2017-09-01 11:55 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Minimal build script source files needed to reproduce the mono icon bug. (21.92 KB, application/x-zip-compressed)
2014-01-21 18:09 UTC, David Grayson
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 17359 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description David Grayson 2014-01-21 18:09:41 UTC
Created attachment 5883 [details]
Minimal build script source files needed to reproduce the mono icon bug.

We distribute a Mono Winforms app and one of our customers recently reported a problem with it that I have not seen before.  I simplified the problem down to just a single C# file and a single resource file and have attached them so you can see the problem too.

I am using Ubuntu 12.04 32-bit virtual machine inside Virtual Box.  The output of "gmcs --version" is "Mono C# compiler version 2.10.8.1" and the output of "mono --version" is "Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1ubuntu2.2)".

When I run the program provided in the attachment, I get this error:

Unhandled Exception: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.CreateFromHandle (IntPtr handle) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Icon.GetInternalBitmap () [0x00000] in <filename unknown>:0 
  at System.Drawing.Icon.ToBitmap () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Icon:ToBitmap ()
  at System.Windows.Forms.XplatUIX11.SetIcon (System.Windows.Forms.Hwnd hwnd, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.SetIcon (IntPtr handle, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI.SetIcon (IntPtr handle, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.CreateHandle () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.CreateControl () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.SetVisibleCore (Boolean value) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
  at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.ShowDialog (IWin32Window owner) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.ShowDialog () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:ShowDialog ()
  at Program.Main () [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: A null reference or invalid value was found [GDI+ status: InvalidParameter]
  at System.Drawing.GDIPlus.CheckStatus (Status status) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.CreateFromHandle (IntPtr handle) [0x00000] in <filename unknown>:0 
  at System.Drawing.Image.LoadFromStream (System.IO.Stream stream, Boolean keepAlive) [0x00000] in <filename unknown>:0 
  at System.Drawing.Icon.GetInternalBitmap () [0x00000] in <filename unknown>:0 
  at System.Drawing.Icon.ToBitmap () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Drawing.Icon:ToBitmap ()
  at System.Windows.Forms.XplatUIX11.SetIcon (System.Windows.Forms.Hwnd hwnd, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUIX11.SetIcon (IntPtr handle, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.XplatUI.SetIcon (IntPtr handle, System.Drawing.Icon icon) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.CreateHandle () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.CreateControl () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.SetVisibleCore (Boolean value) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.SetVisibleCore (Boolean value) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.set_Visible (Boolean value) [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Control:set_Visible (bool)
  at System.Windows.Forms.Application.RunLoop (Boolean Modal, System.Windows.Forms.ApplicationContext context) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.ShowDialog (IWin32Window owner) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Form.ShowDialog () [0x00000] in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) System.Windows.Forms.Form:ShowDialog ()
  at Program.Main () [0x00000] in <filename unknown>:0 

I would have expected the program to just run normally and show blank window on the screen, but it crashes before it can do anything.  If I comment out the line that sets "form.Icon", then the program works correctly (showing a blank window).

There is only one C# file needed to reproduce the problem, and its contents are:

static class Program
{
    [System.STAThread]
    static void Main()
    {
        System.Windows.Forms.Form form = new System.Windows.Forms.Form();
        System.ComponentModel.ComponentResourceManager resources =
            new System.ComponentModel.ComponentResourceManager(typeof(Program));
        System.Drawing.Icon icon = (System.Drawing.Icon)resources.GetObject("$this.Icon");
        System.Console.WriteLine("icon " + icon + " " + (icon == null));
        form.Icon = icon;
        form.ShowDialog();
    }
}


To reproduce this bug:

1) Unzip the file in mono_icon_bug.zip and go into that directory.
2) Run build.sh, a simple shell script that just runs resgen and gmcs.
3) Run "./Program.exe".

I am sorry if this bug has already been fixed; it is not easy for me to run the latest version of Mono.  I suspect this bug report might be a duplicate of https://bugzilla.xamarin.com/show_bug.cgi?id=3961 but that bug report did not have a stack trace so it is hard to tell for sure.
Comment 1 Miguel de Icaza [MSFT] 2014-02-12 17:27:05 UTC
Setting priority to lowest, since Windows.Forms is no longer being developed actively.