B
Bob Dankert
Hello,
I have a control which utilizes the PrintPreviewControl class to provide a
more powerful print preview than the provided PrintPreviewDialog class. I
am having troubles when the default printer on the computer is a network
printer which is not currently accessible (for example, on a laptop removed
from the network). When this happens an exception is thrown while the
PrintPreviewControl is trying to display the print document with details of
the exception being:
Type: System.Exception
Text: No printers are installed
(Stack Trace provided at the end of the message)
The odd part of this is that there are numerous printers installed, however
the default printer happens to not be available since it is a network
printer and is not on the network. I have queried the printer status using
the following WMI query:
SELECT Name, PrinterStatus,Default FROM Win32_Printer
and have found that the PrinterStatus of the default printer is 2 which is
Unknown. It seems to be odd behavior that an exception of "No printers are
installed" is thrown when the PrinterStatus should be Unknown. The real
trouble here is trying to catch and handle these exceptions. Given that the
exception is thrown while trying to display the document and this is done
automatically by the control, I have no idea where I can use a try/catch to
catch this exception and handle it gracefully. Currently I am catching the
error in a try/catch which surrounds the Application.Run command which
starts my program.
After additional testing, I tried taking out the try/catch from around the
Application.Run to see what would happen in debug mode. The results of this
seem even odder to me in that I get a FatalExecutionEngineError being
recorded with the following details:
The runtime has encountered a fatal error. The address of the error was at
0x7f570c2b, on thread 0x197c. The error code is 0xc0000005. This error may
be a bug in the CLR or in the unsafe or non-verifiable portions of user
code. Common sources of this bug include user marshaling errors for
COM-interop or PInvoke, which may corrupt the stack.
If anyone can provide assistance in regards to how I can gracefully handle
or even prevent these exceptions/errors, I would be very much appreciative.
Bob Dankert
Additional Info: This is Windows XP x64 and .Net 2.0
Stack Trace from first "No printers are installed" Exception:
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings
pageSettings)
at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at
System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at System.Windows.Forms.PrintPreviewControl.ComputePreview()
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry
tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at PrintPreviewControl.Program.Main() in
C:\\Programming\\Projects\\PrintPreviewControl\\PrintPreviewControl\\Program.cs:line
19
I have a control which utilizes the PrintPreviewControl class to provide a
more powerful print preview than the provided PrintPreviewDialog class. I
am having troubles when the default printer on the computer is a network
printer which is not currently accessible (for example, on a laptop removed
from the network). When this happens an exception is thrown while the
PrintPreviewControl is trying to display the print document with details of
the exception being:
Type: System.Exception
Text: No printers are installed
(Stack Trace provided at the end of the message)
The odd part of this is that there are numerous printers installed, however
the default printer happens to not be available since it is a network
printer and is not on the network. I have queried the printer status using
the following WMI query:
SELECT Name, PrinterStatus,Default FROM Win32_Printer
and have found that the PrinterStatus of the default printer is 2 which is
Unknown. It seems to be odd behavior that an exception of "No printers are
installed" is thrown when the PrinterStatus should be Unknown. The real
trouble here is trying to catch and handle these exceptions. Given that the
exception is thrown while trying to display the document and this is done
automatically by the control, I have no idea where I can use a try/catch to
catch this exception and handle it gracefully. Currently I am catching the
error in a try/catch which surrounds the Application.Run command which
starts my program.
After additional testing, I tried taking out the try/catch from around the
Application.Run to see what would happen in debug mode. The results of this
seem even odder to me in that I get a FatalExecutionEngineError being
recorded with the following details:
The runtime has encountered a fatal error. The address of the error was at
0x7f570c2b, on thread 0x197c. The error code is 0xc0000005. This error may
be a bug in the CLR or in the unsafe or non-verifiable portions of user
code. Common sources of this bug include user marshaling errors for
COM-interop or PInvoke, which may corrupt the stack.
If anyone can provide assistance in regards to how I can gracefully handle
or even prevent these exceptions/errors, I would be very much appreciative.
Bob Dankert
Additional Info: This is Windows XP x64 and .Net 2.0
Stack Trace from first "No printers are installed" Exception:
at System.Drawing.Printing.PrinterSettings.GetHdevmodeInternal()
at System.Drawing.Printing.PrinterSettings.GetHdevmode(PageSettings
pageSettings)
at System.Drawing.Printing.PrintController.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at
System.Windows.Forms.PrintControllerWithStatusDialog.OnStartPrint(PrintDocument
document, PrintEventArgs e)
at System.Drawing.Printing.PrintController.Print(PrintDocument document)
at System.Drawing.Printing.PrintDocument.Print()
at System.Windows.Forms.PrintPreviewControl.ComputePreview()
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext,
ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry
tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32
dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason, ApplicationContext context)
at PrintPreviewControl.Program.Main() in
C:\\Programming\\Projects\\PrintPreviewControl\\PrintPreviewControl\\Program.cs:line
19