wpf 在 FontFamilyCollection 中找不到 FontFamily 元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48206725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
No FontFamily element found in FontFamilyCollection
提问by user2250152
My WPF application suddenly fails with the following exception:
我的 WPF 应用程序突然失败,出现以下异常:
System.IO.FileFormatException: No FontFamily element found in FontFamilyCollection that matches current OS or greater: Windows7SP1
System.IO.FileFormatException:在 FontFamilyCollection 中找不到与当前操作系统或更高版本匹配的 FontFamily 元素:Windows7SP1
I've tried different OS but it's happening only on Windows 7 with SP1.
我尝试过不同的操作系统,但它只发生在带有 SP1 的 Windows 7 上。
采纳答案by user2250152
I've found out that the exception is connected to the latest security update KB4055532. When this update is uninstalled on Windows 7 SP1 then the problem disappear.
我发现异常与最新的安全更新 KB4055532 相关。在 Windows 7 SP1 上卸载此更新后,问题就会消失。
回答by Boris Makogonyuk
Microsoft released an official statement about this issue here (includes workarounds): https://github.com/dotnet/announcements/issues/53
微软在这里发布了关于这个问题的官方声明(包括解决方法):https: //github.com/dotnet/announcements/issues/53
回答by PatrikE
Since I'm not allowed to comment:
Answer by 'user2250152' is correct.
@Comment by @Lieven Keersmaekers:
'fwiw - installing KB4056894 also triggers this exception when starting Powershell ISE':
I really doubt this.
I'm dealing with this 'KB4055532' issue for 2 days now on all in all 8 machines. But after having installed 'KB4056894' there were no issues with starting Powershell ISE.
This only started to happen after installing 'KB4055532'.
And uninstalling this 'KB4055532' (but still having 'KB4056894' on the machines) resolves the issue with Powershell.
Btw:
There is a hint on the following site (and a way to 'fix' the issue):
https://ngb.to/threads/32709-Microsoft-Patchday-Januar-2018-KB4055532-NET-Font-Probleme.
The issue comes from a '*.CompositeFont' file that gets replaced by the update and which is then missing information for Windows 7. This makes programs based on WPF using functions to determine FontFamily fail/crash.
Effectively I'm quite sure it is only the file 'GlobalUserInterface.CompositeFont' that must be exchanged to temporarily fix this issue.
因为我不允许发表评论:
'user2250152' 的回答是正确的。
@Lieven Keersmaekers
的 @Comment :“fwiw - 安装 KB4056894 也会在启动 Powershell ISE 时触发此异常”:
我真的很怀疑这一点。
我现在在所有 8 台机器上处理这个“KB4055532”问题,为期 2 天。但是在安装了“KB4056894”之后,启动 Powershell ISE 就没有问题了。
这仅在安装“KB4055532”后才开始发生。
卸载这个“KB4055532”(但机器上仍然有“KB4056894”)解决了 Powershell 的问题。
顺便说一句:以下站点上有一个提示(以及一种“解决”问题的方法):
https://ngb。. 该问题来自“*.CompositeFont”文件,该文件被更新替换,然后缺少 Windows 7 的信息。这使得基于 WPF 的程序使用函数来确定 FontFamily 失败/崩溃。
实际上,我很确定只有文件“GlobalUserInterface.CompositeFont”必须被交换才能临时解决这个问题。
回答by jdigital
I ran into this error with MarkdownPad2. With the information from .NET Framework January 2018 Rollup Known Issue KB4074906 - "TypeInitializationException" or "FileFormatException" error in WPF applications(thanks @Boris!), I used the manual repair option to download and replace the corrupted font (installed by Microsoft's update) and it solved the problem.
我在使用 MarkdownPad2 时遇到了这个错误。根据.NET Framework 2018 年 1 月汇总已知问题 KB4074906 - WPF 应用程序中的“TypeInitializationException”或“FileFormatException”错误(感谢 @Boris!)中的信息,我使用手动修复选项下载并替换损坏的字体(由 Microsoft 更新安装) ) 并解决了问题。
The exception looks like this:
异常如下所示:
The invocation of the constructor on type 'MarkdownPad2.UserControls.MarkdownEditor' that matches the specified binding constraints threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Windows.Media.Fonts' threw an exception.
---> System.IO.FileFormatException: No FontFamily element found in FontFamilyCollection that matches current OS or greater: Windows7SP1
The invocation of the constructor on type 'MarkdownPad2.UserControls.MarkdownEditor' that matches the specified binding constraints threw an exception.
---> System.TypeInitializationException: The type initializer for 'System.Windows.Media.Fonts' threw an exception.
---> System.IO.FileFormatException: No FontFamily element found in FontFamilyCollection that matches current OS or greater: Windows7SP1
Damaging a font during an upgrade seems like an inexcusable error. Apparently Microsoft agrees, as they closed the tech note with this comment:
在升级过程中损坏字体似乎是一个不可原谅的错误。显然微软同意,因为他们用以下评论结束了技术说明:
All updates are extensively tested before they are provided to you. We are investigating the gap in our testing and will resolve that for our next release.
所有更新在提供给您之前都经过广泛测试。我们正在调查测试中的差距,并将在我们的下一个版本中解决这个问题。

