[Mono-winforms-list] Probably bug in SetSystemColors

Maser, Dan Dan.Maser at inin.com
Tue May 8 11:47:29 EDT 2007


  I was investigation my colors problem and I noticed this printed to my
console window:
   "Gtk colorscheme read failure, using built-in colorscheme"

  I investigated that code and found a probably bug.  In the file
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs there is
this function, starting near line 207:

private void SetSystemColors(KnownColor kc, Color value)
{
    if (update == null)
    {
       Type known_colors = Type.GetType("System.Drawing.KnownColors," +
Consts.AssemblySystem_Drawing);
       if (known_colors != null)
       {
           update = known_colors.GetMethod("Update", BindingFlags.Static
| BindingFlags.Public);
       }
    }
    if (update != null)
    {
        update.Invoke (null, new object[2] { (int)kc, value.ToArgb() });
    }
}


Which uses reflection to invoke the KnownColors.Update method.   In the
last line the "Color.ToArgb()" function returns an int.  However, the
function signature of Update is:

public static void Update (int knownColor, uint color)
{
    ArgbValues[knownColor] = color;
}

Which expects a uint as the second parameter, not an int.  This throws a
System.ArgumentException.   I verified that if the last line of
SetSystemColors is changed to

    if (update != null)
    {
        update.Invoke (null, new object[2] { (int)kc,
(uint)value.ToArgb() });
    }

Then the exception no longer happens, and the warning is no longer
printed to my console window when launching mono apps.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-winforms-list/attachments/20070508/f52bdb6e/attachment.html 


More information about the Mono-winforms-list mailing list