使用WPF的ShowDialog打开窗体时出现异常

5


我有一个WPF应用程序,在尝试使用ShowDialog()打开一个表单时,我在一台机器上遇到了下面这个奇怪的异常。
您有什么想法可能是问题所在吗?

异常消息 = 操作中止(HRESULT: 0x80004004(E_ABORT)) 异常堆栈跟踪 = 在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) 中抛出异常 在 System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode, IntPtr errorInfo) 中抛出异常 在 MS.Internal.Text.TextInterface.Native.Util.ConvertHresultToException(Int32 hr) 中抛出异常 在 MS.Internal.Text.TextInterface.FontCollection.FindFamilyName(String familyName, UInt32& index) 中查找字体族名称 在 MS.Internal.FontCache.FamilyCollection.LookupFamily(String familyName, FontStyle& fontStyle, FontWeight& fontWeight, FontStretch& fontStretch) 中查找字体族 在 System.Windows.Media.FontFamily.LookupFontFamilyAndFace(CanonicalFontFamilyReference canonicalFamilyReference, FontStyle& style, FontWeight& weight, FontStretch& stretch) 中查找字体和字形 在 System.Windows.Media.FontFamily.FindFirstFontFamilyAndFace(FontStyle& style, FontWeight& weight, FontStretch& stretch) 中查找第一个字体族和字形 在 System.Windows.Media.Typeface.ConstructCachedTypeface() 中构造缓存的字体 在 System.Windows.Media.Typeface.get_CachedTypeface() 中获取缓存的字体 在 MS.Internal.TextFormatting.SimpleTextLine..ctor(FormatSettings settings, Int32 cpFirst, Int32 paragraphWidth, ArrayList runs, Int32& trailing, Int32& trailingSpaceWidth) 中创建简单文本行 在 MS.Internal.TextFormatting.SimpleTextLine.Create(FormatSettings settings, Int32 cpFirst, Int32 paragraphWidth) 中创建简单文本行 在 MS.Internal.TextFormatting.TextFormatterImp.FormatLineInternal(TextSource textSource, Int32 firstCharIndex, Int32 lineLength, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache) 中格式化文本行 在 MS.Internal.TextFormatting.TextFormatterImp.FormatLine(TextSource textSource, Int32 firstCharIndex, Double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache) 中格式化文本行 在 System.Windows.Controls.TextBoxLine.Format(Int32 dcp, Double formatWidth, Double paragraphWidth, LineProperties lineProperties, TextRunCache textRunCache, TextFormatter formatter) 中格式化文本框行 在 System.Windows.Controls.TextBoxView.FullMeasureTick(Double constraintWidth, LineProperties lineProperties) 中测量完整的文本框视图 在 System.Windows.Controls.TextBoxView.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 中使用单个子元素测量元素 在 System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 中测量网格单元格 在 System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 中测量网格单元格组 在 System.Windows.Controls.Grid.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 System.Windows.Controls.Border.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 System.Windows.Controls.Control.MeasureOverride(Size constraint) 中重写测量方法 在 System.Windows.FrameworkElement.MeasureCore(Size availableSize) 中测量核心元素 在 System.Windows.UIElement.Measure(Size availableSize) 中测量 UI 元素 在 System

5
你发的那个错误追踪信息很不错。你看过它了吗?特别是在寻找字体的部分:...at MS.Internal.Text.TextInterface.FontCollection.FindFamilyName(String familyName, UInt32& index)... - Dan J
2
@djacobson:那听起来像是个答案,你想让别人帮你重发吗?还是你自己会这么做? - H.B.
1个回答

7
我曾经遇到过同样的错误,问题出在Windows Presentation Foundation Font Cache Service上。它的缓存文件已经损坏。按照这篇MS KB文章中的说明http://support.microsoft.com/kb/937135,我成功解决了问题。
这适用于Cache的3.0.0.0和4.0.0.0版本。
在找到那篇文章之前,我只是停止并禁用了服务,我的WPF应用程序立即启动了。我怀疑禁用它会导致显示WPF应用程序变慢(本来就很慢),但在几台机器出现这个问题后,我禁用了它,从此没有再出现问题。

我们不得不禁用该服务。 - AMissico

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接