I'm supporting a winforms application using dotnet 3.5 and ComponentFactory Krypton v4.4.0.0, I recently implemented the AppDomain.CurrentDomain.UnhandledException and Application.ThreadException handlers to notify me of exceptions happening on the clients, and found lot of errors showing up in the logs. This one is doing my head in at the moment:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.set_Font(Font value)
at System.Windows.Forms.DataGridViewComboBoxEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyledataGridViewCellStyle)
at System.Windows.Forms.DataGridView.BeginEditInternal(Boolean selectAll)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam,IntPtr lparam)
Note that the stacktrace is entirely in Windows code. There's another that passes through one of my classes:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Font.GetHeight(Graphics graphics)
at System.Drawing.Font.GetHeight()
at System.Drawing.Font.get_Height()
at System.Windows.Forms.Control.set_Font(Font value)
at MyOrg.MyApp.WindowsClient.GuiControls.MaskedTextBoxEditingControl.ApplyCellStyleToEditingControl(DataGridViewCellStyledataGridViewCellStyle)
at System.Windows.Forms.DataGridView.BeginEditInternal(Boolean selectAll)
at System.Windows.Forms.DataGridView.ProcessKeyEventArgs(Message& m)
at System.Windows.Forms.Control.ProcessKeyMessage(Message& m)
at System.Windows.Forms.Control.WmKeyChar(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Here's the code for that snippet:
public void ApplyCellStyleToEditingControl(DataGridViewCellStyle dataGridViewCellStyle)
{
this.Font = dataGridViewCellStyle.Font;
this.ForeColor = dataGridViewCellStyle.ForeColor;
this.BackColor = dataGridViewCellStyle.BackColor;
this.TextAlign = translateAlignment(dataGridViewCellStyle.Alignment);
}
which doesn't tell me much.
The "System.ArgumentException: Parameter is not valid." error is pretty woeful and gives me very little to go on, but using dotPeek I looked at the code for Font.Get_Height(Graphics g) and discovered it's a GDI+ error, specifically GetFontHeight:
public float GetHeight(Graphics graphics)
{
if (graphics == null)
{
throw new ArgumentNullException("graphics");
}
else
{
float size;
int fontHeight = SafeNativeMethods.Gdip.GdipGetFontHeight(new HandleRef((object) this, this.NativeFont), new HandleRef((object) graphics, graphics.NativeGraphics), out size);
if (fontHeight != 0)
throw SafeNativeMethods.Gdip.StatusException(fontHeight);
else
return size;
}
}
which is this GDI+ method: http://www.jose.it-berater.org/gdiplus/reference/flatapi/font/gdipgetfontheight.htm
and my status error is Invalidparameter, as documented here: http://msdn.microsoft.com/en-us/library/windows/desktop/ms534175(v=vs.85).aspx
Unfortunately none of this helps me to resolve what's wrong with the Graphics object. This is coming from unhandled exceptions from users in the field. I recently had a memory leak that was caused by a leaking EventHandler and consuming all the available GDI handles, but I've fixed that, so now I'm not sure whether this is a memory leak, a GDI handle leak, or just bad config somewhere that's triggered by users doing something out of the ordinary.
anyone have any ideas? Help much appreciated!