Thursday 27 February 2014

WPF PasswordBox control click crashes Application if Fonts aren’t available

I recently had an issue where a kiosk application I was developing would crash on a Windows Embedded 7 system, if the user clicked on a PasswordBox control. Annoyingly, I couldn’t replicate this in my test environment.

The Application would crash, and frustratingly, not actually hit any of my Error Handlers. However, the Windows Application Event Log shined a little more on the issue, returning the following;

Application: FrontEnd.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Unrecoverable system error.
Stack:
   at System.Environment.FailFast(System.String)
   at MS.Internal.Invariant.FailFast(System.String, System.String)
   at MS.Internal.Invariant.Assert(Boolean)
   at System.Windows.Media.FontFamily.get_FirstFontFamily()
   at System.Windows.Media.FontFamily.get_LineSpacing()………

After doing some digging around, I found that I wasn’t the only person that this had happened to;

http://stackoverflow.com/questions/8821648/why-does-a-passwordbox-control-crash-my-wpf-application

and…

http://social.msdn.microsoft.com/Forums/vstudio/ar-SA/fc2c9a54-8f66-4f1a-82be-cb40ada5fba5/systemwindowsmediafontfamily-crash-net-35-sp1-systemexecutionengineexception?forum=wpf

Where the final post by Brendave suggested installing the following fonts on the machine;

  • Arial (TrueType)
  • Courier New (TrueType)
  • Times New Roman (TrueType)
  • Marlette

I couldn’t actually find Marlette on my system, so didn’t copy this one, and I also assumed that if it was working ok on my system anyway, then chances were this Font being missing wasn’t the issue.

After installing these fonts, magically the issue was solved.