Tuesday 28 July 2015

WPF and broken fonts


Today I had problems with starting up the Work Item Template editor in Visual Studio, and when I tried repairing my VS installation the installer kept crashing!

TL;DR:
If you have broken fonts in your Windows installation, running WPF apps (or running apps that use WPF like Visual Studio) will unexpectedly crash with a Type Initializer exception.
That will keep happening until you fix your fonts.



The installer logs the errors that the installer runs into. It logs to c:\users\he152234\appdata\local\temp\dd_vs_[xyz]_[date].log.

My VS installer was crashing with this error:
[0A94:25CC][2015-07-28T16:08:47]e000: MUX:  ERROR: The type initializer for 'System.Windows.Media.FontFamily' threw an exception.
[0A94:25CC][2015-07-28T16:08:47]e000: MUX:  Stack:    at System.Windows.Media.Typeface..ctor(FontFamily fontFamily, FontStyle style, FontWeight weight, FontStretch stretch)

It turns out VS’s installer is a WPF application and WPF apps are susceptible to broken fonts.

So.. what worked for me was:
Open cmd.exe and copy all files from c:\windows\fonts to some other folder (c:\fonts for me).
Open regedit and navigate to HKLM\Software\Microsoft\Windows NT\CurrentVersion\Fonts
Delete all font registrations (a little scary).

Open Fonts in Control Panel.
Drag all fonts from c:\fonts to the Control Panel Fonts window (this re-registers all valid fonts).
Restart the computer.

And I can run VS again! :)



Dave