List Info

Thread: Probably bug in SetSystemColors




Probably bug in SetSystemColors
country flaguser name
United States
2007-05-08 10:47:29

  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.

Re: Probably bug in SetSystemColors
country flaguser name
Canada
2007-05-08 12:10:09
On Tue, 2007-05-08 at 11:47 -0400, Maser, Dan wrote:
> 
>   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.c
s 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; 
> }

This has been changed, last week, to accept an int.

> 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.

Just update from SVN and this should work without problem.

-- 
Sebastien Pouliot  <sebastienximian.com>
Blog: http://pages.infinit.
net/ctech/

_______________________________________________
Mono-winforms-list maillist  -  Mono-winforms-listlists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-winform
s-list

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )