I am making a .NET Core 3.1 WPF App its building successfully! But when I run a custom print function which is using System.Drawing it throw this error:
Exception thrown: 'System.IO.FileNotFoundException' in System.Drawing.Common.dll
I even tried to install via NuGet:
App is building successfully but when I try to run the print function it throw error and print blank page.
Funny thing is same codes are working with a console app
Below is detail about console app
Same Version Of System.Drawing.Common also not working
##Code For Print Function >>
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);
}
}
CodePudding user response:
The issue you have is that the path
in WPF version will not be found, see
Bitmap.FromFile(path, false)
,
not the problem with System.Drawing.Common.dll
Ensure there is a file for path
.