问题背景
公司线上最新的安装包,有公司内部的小伙伴安装后不能不行,现象为:双击后应用程序直接崩溃。查看了window 日志,内容为:
应用程序: YNBlackboard47.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.NullReferenceException
在 MS.Internal.FontCache.FontFaceLayoutInfo+IntMap.TryGetValue(Int32, UInt16 ByRef)
在 System.Windows.Media.GlyphTypeface.Initialize(System.Uri, System.Windows.Media.StyleSimulations)
在 MS.Internal.Xaml.Runtime.ClrObjectRuntime.InitializationGuard(System.Xaml.XamlType, System.Object, Boolean)
在 System.Xaml.XamlObjectWriter.Logic_EndInit(MS.Internal.Xaml.Context.ObjectWriterContext)
在 System.Xaml.XamlObjectWriter.WriteEndObject()
在 System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlReader, System.Xaml.XamlObjectWriter)
在 System.Windows.FrameworkTemplate.LoadTemplateXaml(System.Xaml.XamlObjectWriter)
在 System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(System.Windows.DependencyObject, System.Windows.Markup.IComponentConnector, System.Windows.Markup.IStyleConnector, System.Collections.Generic.List`1<System.Windows.DependencyObject>, System.Windows.UncommonField`1<System.Collections.Hashtable>)
在 System.Windows.FrameworkTemplate.LoadContent(System.Windows.DependencyObject, System.Collections.Generic.List`1<System.Windows.DependencyObject>)
在 System.Windows.StyleHelper.ApplyTemplateContent(System.Windows.UncommonField`1<System.Collections.Specialized.HybridDictionary[]>, System.Windows.DependencyObject, System.Windows.FrameworkElementFactory, Int32, System.Collections.Specialized.HybridDictionary, System.Windows.FrameworkTemplate)
在 System.Windows.FrameworkTemplate.ApplyTemplateContent(System.Windows.UncommonField`1<System.Collections.Specialized.HybridDictionary[]>, System.Windows.FrameworkElement)
在 System.Windows.FrameworkElement.ApplyTemplate()
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.StackPanel.StackMeasureHelper(System.Windows.Controls.IStackMeasure, System.Windows.Controls.IStackMeasureScrollData, System.Windows.Size)
在 System.Windows.Controls.StackPanel.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.Control.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.Grid.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 MS.Internal.Helper.MeasureElementWithSingleChild(System.Windows.UIElement, System.Windows.Size)
在 System.Windows.Controls.ContentPresenter.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.Decorator.MeasureOverride(System.Windows.Size)
在 System.Windows.Documents.AdornerDecorator.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Controls.Border.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Window.MeasureOverrideHelper(System.Windows.Size)
在 System.Windows.Window.MeasureOverride(System.Windows.Size)
在 System.Windows.FrameworkElement.MeasureCore(System.Windows.Size)
在 System.Windows.UIElement.Measure(System.Windows.Size)
在 System.Windows.Interop.HwndSource.SetLayoutSize()
在 System.Windows.Interop.HwndSource.set_RootVisualInternal(System.Windows.Media.Visual)
在 System.Windows.Window.SetRootVisual()
在 System.Windows.Window.SetRootVisualAndUpdateSTC()
在 System.Windows.Window.SetupInitialState(Double, Double, Double, Double)
在 System.Windows.Window.CreateSourceWindow(Boolean)
在 System.Windows.Window.ShowHelper(System.Object)
在 YNBlackboard.StartUp+<Window_Loaded>d__34.MoveNext()
在 System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0(System.Object)
在 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
在 System.Windows.Threading.DispatcherOperation.InvokeImpl()
在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
在 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)
在 MS.Internal.CulturePreservingExecutionContext.Run(MS.Internal.CulturePreservingExecutionContext, 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)
在 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
在 System.Windows.Threading.Dispatcher.LegacyInvokeImpl(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.Application.RunDispatcher(System.Object)
在 System.Windows.Application.RunInternal(System.Windows.Window)
在 YNBlackboard.App.Main()
错误提醒:
异常信息: System.NullReferenceException 在 MS.Internal.FontCache.FontFaceLayoutInfo+IntMap.TryGetValue(Int32, UInt16 ByRef)
修复过程
首先重新安装了下net 4.5.2的环境,安装后运行程序仍然报错。然后又在win7个性化设置里面设置了字体,在其他电脑拷贝了宋体字体覆盖到问题电脑,使用Windows Aero (Tahoma Font).exe主题修改
这些方法都不行。仍然报错…
最终解决办法
修复win7注册表:使用系统自带字体的注册表对问题机器进行注册表合并。然后运行软件,完美解决。注册表如下:
Windows Registry Editor Version 5.00
;Restores default system font setting (to Segoe UI) in Windows 7
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
“Segoe UI (TrueType)”=“segoeui.ttf”
“Segoe UI Bold (TrueType)”=“segoeuib.ttf”
“Segoe UI Bold Italic (TrueType)”=“segoeuiz.ttf”
“Segoe UI Italic (TrueType)”=“segoeuii.ttf”
“Segoe UI Light (TrueType)”=“segoeuil.ttf”
“Segoe UI Semibold (TrueType)”=“seguisb.ttf”
“Segoe UI Symbol (TrueType)”=“seguisym.ttf”
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes]
“Segoe UI”=-
把上面文本,保存为xxxx.reg
然后进行注册表合并