Note that there are some explanatory texts on larger screens.

plurals
  1. POFramework crash when printing an XPS document
    primarykey
    data
    text
    <p>I have a .NET 4.0 application that sends FixedDocument objects to a printer using an XpsDocumentWriter. I have encountered an application crash in a few scenarios. As far as I can tell it is a compatibility issue with XPS and certain print drivers. I am including a stack trace below. I would like to either make it work properly or identify the problem before the crash so I can prevent users from attempting to print to a printer that will cause an application crash. I am unable to catch the exception in a try catch block since the exception is thrown on another thread in some external code.</p> <p>My code looks similar to this:</p> <pre><code>Dim printQueue as PrintQueue 'initialize printQueue Dim printDocument as FixedDocument 'initialize printDocument 'add content to printDocument Dim writer As XpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue) AddHandler writer.WritingCompleted, AddressOf WriteDocumentComplete writer.WriteAsync(printDocument, printQueue.UserPrintTicket) </code></pre> <p>I have tried looking in the registry to determine if a print driver is based on Microsofts Universal Print Driver, but that doesn't seem like a reliable method. I have some printers that don't appear to have an explicit dependency that work fine.</p> <blockquote> <p>HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Environments\Windows NT x86\Drivers\Version-3\Microsoft XPS Document Writer</p> </blockquote> <p>Stack Trace from the Application Event Log:</p> <blockquote> <p>Application: MyApp.exe Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.InvalidOperationException Stack: at Microsoft.Internal.AlphaFlattener.MetroDevice0.AssertState(DeviceState, DeviceState) at Microsoft.Internal.AlphaFlattener.MetroToGdiConverter.EndDocument() at System.Windows.Xps.Serialization.NgcSerializationManagerAsync.EndDocument(Boolean) at System.Windows.Xps.Serialization.NgcSerializationManagerAsync.InvokeSaveAsXamlWorkItem(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object) at System.Threading.ExecutionContext.runTryCode(System.Object) at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode, CleanupCode, System.Object) at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) at System.Windows.Threading.DispatcherOperation.Invoke() at System.Windows.Threading.Dispatcher.ProcessQueue() at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) at System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) at MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef) at System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame) at System.Windows.Threading.Dispatcher.Run() at System.Windows.Application.RunDispatcher(System.Object) at System.Windows.Application.RunInternal(System.Windows.Window) at System.Windows.Application.Run(System.Windows.Window) at System.Windows.Application.Run() at MyApp.Application.Main()</p> <p>For more information, see Help and Support Center at <a href="http://go.microsoft.com/fwlink/events.asp" rel="nofollow">http://go.microsoft.com/fwlink/events.asp</a>.</p> </blockquote> <p><strong>Update:</strong> I spoke with Microsoft. I was told that there is no work around and it will be fixed in .NET 4.5.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload