Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Exception thrown: 'System.IO.FileNotFoundException' in System.Drawing.Common.dll

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

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

enter image description here

enter image description here

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);
            }
        }

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading