【发布时间】:2022-01-18 12:53:34
【问题描述】:
我正在成功构建一个 .NET Core 3.1 WPF 应用程序!但是当我运行一个使用 System.Drawing 的自定义打印函数时,它会抛出这个错误:
Exception thrown: 'System.IO.FileNotFoundException' in System.Drawing.Common.dll
我什至尝试通过 NuGet 安装:
应用程序构建成功,但是当我尝试运行打印功能时,它会抛出错误并打印空白页。
有趣的是,相同的代码正在与控制台应用程序一起使用
以下是有关控制台应用程序的详细信息
相同版本的 System.Drawing.Common 也不起作用
##打印功能代码>>
public static void Print()
{
PrintDocument p = new PrintDocument();
p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
{
graphics = e1.Graphics;
Bitmap logo = (Bitmap)Bitmap.FromFile(path, false);
graphics.DrawImage(logo, new Point(25, (int)Offset));
layout = new RectangleF(new PointF(startX + 75, startY + Offset + 25), layoutSize);
graphics.DrawString("Receipt", font10, brush, layout, formatCenter);
};
try
{
p.Print();
}
catch (Exception ex)
{
Console.WriteLine("Exception Occured While Printing \n" + ex);
}
}
【问题讨论】:
-
如果在两种情况下都使用相同版本的 System.Drawing.Common,问题是否存在?
-
我试过同样的版本也不能用
-
你能提供你的代码吗?
-
@Llama 添加了代码...