执行使用ZXing.net创建条形码的asp.net页面时,它在Windows 10计算机上运行正常,但在Windows 2012服务器上运行不正常。在服务器上引发以下错误。
代码:
Image imgBarCode = new Image();
var codabar = new ZXing.BarcodeWriter();
codabar.Options = options;
codabar.Format = ZXing.BarcodeFormat.CODE_128;
using (Bitmap bitMap = new Bitmap(codabar.Write(customerID.Trim())))
{
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
byte[] byteImage = ms.ToArray();
imgBarCode.ImageUrl = "data:image/jpeg;base64," + Convert.ToBase64String(byteImage);
}
panelGeneralInfo.Controls.Add(imgBarCode);
}
'ZXing.Rendering.BitmapRenderer'的类型初始值设定项引发异常。
System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. --->
System.TypeInitializationException: The type initializer for 'ZXing.Rendering.BitmapRenderer' threw an exception. --->
System.ArgumentException: Font 'Arial' does not support style 'Regular'.
at System.Drawing.Font.CreateNativeFont()
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font.Initialize(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style)
at ZXing.Rendering.BitmapRenderer..cctor() in C:\ZXing.Net.0.14.0.0\Source\lib\renderer\BitmapRenderer.cs:line 56 --- End of inner exception stack trace ---
at ZXing.Rendering.BitmapRenderer..ctor() in C:\ZXing.Net.0.14.0.0\Source\lib\renderer\BitmapRenderer.cs:line 65
at ZXing.BarcodeWriter..ctor() in C:\ZXing.Net.0.14.0.0\Source\lib\BarcodeWriter.cs:line 112
答案 0 :(得分:0)
重新启动IIS解决了这个问题。显然,.net框架创建的堆栈跟踪有点误导!