WPF 在 XP 中以 120 DPI 失败,但在 96 DPI 下则不然
这很奇怪。我有一个 WPF 应用程序,当 DPI 设置为 96 时,它在 XP 中工作得很好,但当 DPI 设置为 120 时,它就失败了。我在两台单独的 XP 计算机上尝试了此操作,得到了相同的结果。
该错误就在加载异常处理程序之前的初始化时发生。
你能给我一些关于如何调试这个的提示吗?这是事件日志条目之一。
Event Type: Error
Event Source: .NET Runtime
Event Category: None
Event ID: 1026
Date: 11/17/2010
Time: 7:37:15 PM
User: N/A
Computer: EXIDA-100A3799C
Description:
Application: exSILentia3.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileFormatException
Stack:
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 exSILentia3.Application.Main()
This is odd. I have a WPF application that works just fine in XP when the DPI is set to 96, but it fails with it set to 120. I tried this on two separate XP machines with the same results.
The error is right at initialize, prior to loading my exception handler.
Can you give me some tips on how I can debug this? Here is one of the the Event Log entries.
Event Type: Error
Event Source: .NET Runtime
Event Category: None
Event ID: 1026
Date: 11/17/2010
Time: 7:37:15 PM
User: N/A
Computer: EXIDA-100A3799C
Description:
Application: exSILentia3.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileFormatException
Stack:
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 exSILentia3.Application.Main()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否在相关计算机上安装了 Visual Studio?如果是这样,我建议在调试器中运行,并将其配置为在引发异常时立即中断。从“调试”菜单中,打开“异常”对话框,展开“公共语言运行时异常”项,然后展开“System.IO”部分以查找“System.IO.FileFormatException”项。确保选中第一列(抛出)。
我建议这样做的原因是您显示的堆栈跟踪看起来像重新抛出的堆栈,而不是原始异常。异常是从
MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen
方法引发的,该方法是检测未处理异常的 WPF 消息循环位。因此,在日志中显示的内容没有什么用处 - 您真正想知道的是在 WPF 捕获异常之前最初从何处引发异常。如果您要求调试器在抛出异常后立即停止,您就可以做到这一点。这应该能让问题得到更多的了解。
如果这不是一个选项,您可以尝试将处理程序附加到
Dispatcher.UnhandledException
事件或Application.DispatcherUnhandledException
事件,并添加一些您自己的自定义日志记录代码。这可能会为您提供有关异常最初从何处抛出的更多信息。在没有更详细的日志记录的情况下,我想到的显而易见的事情是(尽管可能性不大):您的任一系统上是否安装了任何不寻常的字体?
Do you have Visual Studio installed on either of the machines in question? If so, I'd recommend running within the debugger, and configuring it to break as soon as the exception is thrown. From the Debug menu, open the Exceptions dialog, expand the Common Language Runtime Exceptions item, and then expand the System.IO section to find the System.IO.FileFormatException item. Ensure the first column (Thrown) is checked.
The reason I suggest this is that the stack trace you've shown looks like the stack for a rethrow, rather than the original exception. The exception is being thrown from the
MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen
method, which is the bit of the WPF message loop that detects unhandled exceptions. So that's not a useful thing to have shown up in the log - what you really want to know is where the exception was originally thrown from before WPF caught it. And you'll be able to do that if you ask the debugger to stop as soon as that exception is thrown.That should shed more light on the issue.
If that's not an option, you might try attaching a handler to the
Dispatcher.UnhandledException
event, or theApplication.DispatcherUnhandledException
event and adding some custom logging code of your own. That might provide you with more information about where the exception was originally thrown from.In the absence of more detailed logging, the obvious thing that occurs to me is this (although it's a long shot): do you have any unusual fonts installed on either system?
感谢您的帮助。内部异常是一个更多的帮助,因为它将其限制为位图文件错误。
我最终通过删除该项目的副本直到它起作用来解决这个问题。这个问题就摆在我面前。当应用程序加载时,它会加载一个主窗口。我很早就删除了该窗口的图标,但没有成功。直到后来我转回来并删除了对它加载的窗口中的图标的引用(谢天谢地),我快要疯了。也许它在 Windows 资源中缓存了已删除图标的副本?
不管怎样,我使用了我们的图标编辑器(Axialis IconWorkshop)来确保每种可能的图标格式都存在;没有成功。
我最终只是让窗口保持无图标状态,并尝试在加载时加载图标,如果失败,我只是无图标运行。这并不完美,但在图标导致问题的有限情况下,我不希望它因此崩溃。
顺便说一句,我还尝试加载较旧/较低的分辨率。版本的图标,如果第一个失败,并且在这种情况下确实有效。
我只是希望调试器能够提供更多帮助来查明这一点。
Thank you, for your help. The Inner Exception, was a touch more help in that it limited it to a Bitmap file error.
I eventually figured it out by gutting the copy of the project until it worked. The problem was starring me in the face. When the app loads it loads a main window. I deleted the Icon for this window early on, with no success. It wasn't until later that I circled back and also deleted the reference to the icon in the window that it loaded (Thank goodness), I was going insane. Perhaps it cached a copy of the removed icon in the Windows resources?
Anyway, I used our icon editor (Axialis IconWorkshop) to make sure every possible icon format was present; with no success.
I eventually just left the window iconless, and attempt to load the icon at load, if it fails, I just run iconless. This is not perfect, but in the limited situations where the icon causes a problem, I don't want it to crash for that.
On a side note, I had it also try to load an older/lower res. version of the icon, if the first one fails, and that does work in this situation.
I just wish the debugger was more help in pinpointing this.
您可能想查看图标的格式。我在 Vista 之前的平台上使用高分辨率 256 图标的 WPF 应用程序时遇到问题。我的设计团队提供了一个图标,该图标使用 PNG 格式作为 256 图标,旧平台无法加载。一旦该特定图标更改为位图格式,一切都很好。
You may want to look at the format of your icons. I had issues with a WPF app on pre-Vista platforms with the high res 256 icon. My design team supplied an icon which used PNG format for the 256 icon which older platforms couldn't load. Once that particular icon was changed to the bitmap format everything was fine.