Hi Team,
We are an existing customer of Dynamic PDF Print Manager.
Our system is currently on version 4.7.0.39844.
When attempting to print with an unavailable printer, the PrintJob.Dispose() method crashes our application. We are receiving a NullReferenceException. We wrote a quick console app that reproduces this. See the code and output below. Attempting to print to an unavailable printer is a valid use case and we handle those exceptions if we could catch them without crashing the app.
OUTPUT:
Exception: The printer named "Kyocera" could not be opened. Error code: 1801.
Unhandled Exception: NullReferenceException
Message: Object reference not set to an instance of an object.
Source: DynamicPDF.Printing.NETFramework40
Stack: at ceTe.DynamicPDF.Printing.PrintJob.Dispose(Boolean disposing)
at ceTe.DynamicPDF.Printing.PrintJob.Finalize()
CODE (It has been through many iterations to try and catch the exception, we've tried a using block with no luck):
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; // Try to catch it (or at least see it here)
PrintJob pj = new PrintJob("Kyocera"); // This is an unavailable printer name
pj.PrintOptions.DuplexMode = DuplexMode.DuplexVertical;
pj.PrintOptions.Color = true;
pj.PrintOptions.Scaling = PageScaling.ActualSize;
//pj.Failed += Pj_Failed; //Does not get called
pj.DocumentName = $"TEMP PDF.pdf";
Console.WriteLine($"Printing set {pj.DocumentName}...");
var data = LoadPdfData(); // Get some pdf data.
var page = new InputPdf(data);
pj.Pages.Add(page);
pj.Print();
try
{
page.Dispose();
pj.Dispose();
}
catch (NullReferenceException ex)
{
log($"NullReferenceException {ex.Message}."); // We DO NOT this in output
}
log($"Print done {pj.DocumentName}.");
}
catch (Exception ex)
{
log($"Exception {ex.Message}."); // We see this in output
}
//We have this setup as our unhandled exception handler and it is in terminating state when it is thrown from the PrintManager
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is Exception)
{
Logging.LogException(e.ExceptionObject as Exception);
if (e.IsTerminating)
Console.WriteLine("Noooooooo...........");
}
}
Please advise.