开发者

Framework crash when printing an XPS document

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.

My code looks similar to this:

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)

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.

HKEY_LOCAL_MACHINE\SYSTEM\ControlSe开发者_Go百科t001\Control\Print\Environments\Windows NT x86\Drivers\Version-3\Microsoft XPS Document Writer

Stack Trace from the Application Event Log:

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()

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

Update: I spoke with Microsoft. I was told that there is no work around and it will be fixed in .NET 4.5.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜