Generic Error in GDI+ from Graphics.DrawString()



We are experiencing an issue where Graphics.DrawString will throw an
exception stating that "A generic error occurred in GDI+". The call stack
follows at the end of the post.

The issue is not caused by lack of resources or resource leaks. At the time
of exception, GDI resource and handle usage is very low.

The circumstances under which we have been able to reliably reproduce this
issue have been:
- Terminal services is involved. Most often, the exception occurs after
a terminal services connection has been made to a Windows XP machine,
disconnected, and the code has subsequently executed. We experience this
during our automated unit tests. Occasionally, the error has occurred while
the terminal services connection is still active, though it is not as
- We are calling DrawString with a width and a height not large enough
to display all of the test passed in. In our reproducible case, we are
drawing 193 characters on an area 79 pixels wide, 14 pixels high with an 8
point font. Drawing 192 characters succeeds, 193 characters fails reliably.
This occurs regardles of the character width - ie 193 'x's or 193 'i's both
reproduce the problem.

Can anyone shed any light on this problem? We have seen it in a few places
around the net, including Dante's post in this newsgroup, but have not seen
any explanations or solutions. We can't really tell much about the error
from the exception (except that it's generic).



Call stack:

System.Runtime.InteropServices.ExternalException: A generic error occurred
in GDI+.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush,
RectangleF layoutRectangle, StringFormat format)
at Enterprise.Core.Forms.OGridTextBoxColumn.PaintText(Graphics Graphics,
Rectangle Bounds, String CellText, Brush BackBrush, Brush ForeBrush, Boolean
IsRightToLeft, Boolean UseEllipsis)
at Enterprise.Core.Forms.OGridTextBoxColumn.PaintText(Graphics Graphics,
Rectangle Bounds, String CellText, Brush BackBrush, Brush ForeBrush, Boolean
at Enterprise.Core.Forms.OGridTextBoxColumn.Paint(Graphics Graphics,
Rectangle Bounds, CurrencyManager Source, Int32 PaintingRowNum, Brush
BackBrush, Brush ForeBrush, Boolean IsAlignedToRight)
System.Windows.Forms.DataGridRelationshipRow.PaintCellContents(Graphics g,
Rectangle cellBounds, DataGridColumnStyle column, Brush backBr, Brush
foreBrush, Boolean alignToRight)
at System.Windows.Forms.DataGridRow.PaintData(Graphics g, Rectangle
bounds, Int32 firstVisibleColumn, Int32 columnCount, Boolean alignToRight)
at System.Windows.Forms.DataGridRelationshipRow.Paint(Graphics g,
Rectangle bounds, Rectangle trueRowBounds, Int32 firstVisibleColumn, Int32
numVisibleColumns, Boolean alignToRight)
at System.Windows.Forms.DataGrid.PaintRows(Graphics g, Rectangle&
at System.Windows.Forms.DataGrid.PaintGrid(Graphics g, Rectangle
at System.Windows.Forms.DataGrid.OnPaint(PaintEventArgs pe)
at Enterprise.ZArchitecture.ZGrid.OnPaint(PaintEventArgs e)
at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e,
Int16 layer, Boolean disposeEventArgs)
at System.Windows.Forms.Control.WmPaint(Message& m)


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question