Reputation: 13945
I should say first that I have found and read most (if not all) of the questions with the same error message. So far, none of lead to a solution. Most seemed to be aimed at IIS hosted apps. And the ones that are Azure hosted are old and just don't have solutions, or have dead links to old articles that no longer exist.
The error is sporadic. And, the error is happening only in Prod. We are not able to reproduce in QA or in Dev or in Local. The errors began immediately after pushing a release that contained an upgrade from .NET Framework 4.7 to .NET Framework 4.8. (No other changes in this release). So, obviously, there is some difference between QA and Prod, but so far we can't track it down.
Some of the other posts on this same error have indicated that it's a permissions issue. We have checked the permissions on everything we can think of, and they are the same between the QA and Prod. That being said, our Azure guy is (as I type) doing his best to compare everything he can think of between QA and Prod to find any differences.
Our method is generating a bar code. The error is on this line:
graphic.DrawString(string.Format("*{0}*", Code), newFont, black, point);
Here is the entire method:
(Please note that we are aware that some of this code can be cleaned up with newer versions of C#. We're working on that!)
public static byte[] BarcodeImageGenerator(string Code)
{
byte[] BarCode;
int Height; // = 50
int Width;// = 100
Code = Code.ToUpper();
PrivateFontCollection customfont = new PrivateFontCollection();
customfont.AddFontFile(string.Format("{0}{1}", HttpRuntime.AppDomainAppPath, "fonts\\FRE3OF9X.TTF"));
Font newFont = new Font(customfont.Families[0], 60, FontStyle.Regular);
SizeF stringSize = Graphics.FromImage(new Bitmap(1, 1)).MeasureString(Code, newFont);
Width = (int)stringSize.Width + 50;
Height = (int)stringSize.Height;
Bitmap objBitmap = new Bitmap(Width, Height);
using (Graphics graphic = Graphics.FromImage(objBitmap))
{
PointF point = new PointF(2f, 2f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, objBitmap.Width, objBitmap.Height);
graphic.DrawString(string.Format("*{0}*", Code), newFont, black, point);
}
using (MemoryStream Mmst = new MemoryStream())
{
objBitmap.Save(Mmst, ImageFormat.Jpeg);
BarCode = Mmst.GetBuffer();
return BarCode;
}
}
Here are the first few lines of the stack trace:
System.Runtime.InteropServices.ExternalException (0x80004005): 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 System.Drawing.Graphics.DrawString(String s, Font font, Brush brush, PointF point)
Upvotes: 0
Views: 36