It has been found that rendering a TextAnnotation can, at times, cause a System.ArgumentException when the Graphics.DrawString method is used. This is not specific to DotAnnotate and appears to be a bug in the .NET Framework.
The exception will appear as follows:
System.ArgumentException: Parameter is not valid.
at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
at Atalasoft.Imaging.Annotate.TextAnnotation.Paint(Graphics graphics, PointF offset, PointF zoom, Single resolution)
This seems to only happen when a brush from the static Brushes object is used. For example:
TextAnnotation ann = new TextAnnotation("My Text", font, Brushes.Black, null, null);
This can be resolved by creating a new SolidBrush instead:
TextAnnotation ann = new TextAnnotation("My Text", font, new SolidBrush(Color.Black), null, null);