打印XPS文档时框架崩溃

时间:2011-08-11 14:12:57

标签: .net printing xps

我有一个.NET 4.0应用程序,它使用XpsDocumentWriter将FixedDocument对象发送到打印机。我在几个场景中遇到了应用程序崩溃。据我所知,这是XPS和某些打印驱动程序的兼容性问题。我在下面包含一个堆栈跟踪。我想要让它正常工作或在崩溃之前找出问题所以我可以阻止用户尝试打印到会导致应用程序崩溃的打印机。我无法在try catch块中捕获异常,因为异常会在某些外部代码中的另一个线程上抛出。

我的代码与此类似:

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)

我试过在注册表中查看打印驱动程序是否基于微软通用打印驱动程序,但这似乎不是一种可靠的方法。我有一些打印机看起来没有明确的依赖,工作正常。

  

HKEY_LOCAL_MACHINE \ SYSTEM \ ControlSet001 \ Control \ Print \ Environments \ Windows NT x86 \ Drivers \ Version-3 \ Microsoft XPS Document Writer

应用程序事件日志中的堆栈跟踪:

  

应用程序:MyApp.exe   框架版本:v4.0.30319   描述:由于未处理的异常,进程终止。   异常信息:System.InvalidOperationException   堆:      在Microsoft.Internal.AlphaFlattener.MetroDevice0.AssertState(DeviceState,DeviceState)      在Microsoft.Internal.AlphaFlattener.MetroToGdiConverter.EndDocument()      在System.Windows.Xps.Serialization.NgcSerializationManagerAsync.EndDocument(布尔)      在System.Windows.Xps.Serialization.NgcSerializationManagerAsync.InvokeSaveAsXamlWorkItem(System.Object)      在System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)      在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)      在System.Windows.Threading.DispatcherOperation.InvokeImpl()      在System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(System.Object)      在System.Threading.ExecutionContext.runTryCode(System.Object)      在System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode,CleanupCode,System.Object)      在System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)      在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object,Boolean)      在System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext,System.Threading.ContextCallback,System.Object)      在System.Windows.Threading.DispatcherOperation.Invoke()      在System.Windows.Threading.Dispatcher.ProcessQueue()      在System.Windows.Threading.Dispatcher.WndProcHook(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)      在MS.Win32.HwndWrapper.WndProc(IntPtr,Int32,IntPtr,IntPtr,Boolean ByRef)      在MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)      在System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate,System.Object,Int32)      在MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object,System.Delegate,System.Object,Int32,System.Delegate)      在System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority,System.TimeSpan,System.Delegate,System.Object,Int32)      在MS.Win32.HwndSubclass.SubclassWndProc(IntPtr,Int32,IntPtr,IntPtr)      在MS.Win32.UnsafeNativeMethods.DispatchMessage(System.Windows.Interop.MSG ByRef)      在System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame)      在System.Windows.Threading.Dispatcher.PushFrame(System.Windows.Threading.DispatcherFrame)      在System.Windows.Threading.Dispatcher.Run()      在System.Windows.Application.RunDispatcher(System.Object)      在System.Windows.Application.RunInternal(System.Windows.Window)      在System.Windows.Application.Run(System.Windows.Window)      在System.Windows.Application.Run()      在MyApp.Application.Main()

     

有关详细信息,请参阅http://go.microsoft.com/fwlink/events.asp上的“帮助和支持中心”。

更新 我和微软谈过。我被告知没有解决方法,它将在.NET 4.5中修复。

0 个答案:

没有答案
相关问题