0

I'm getting this exception in my WPF app on one particular PC, on half a dozen others it runs fine. Here is the full exception trace:

System.Windows.Markup.XamlParseException: The type initializer for 'System.Windows.Window' threw an exception. 
---> System.TypeInitializationException: The type initializer for 'System.Windows.FrameworkElement' threw an exception. 
---> System.TypeInitializationException: The type initializer for 'System.Windows.Documents.TextElement' threw an exception. 
---> System.TypeInitializationException: The type initializer for 'MS.Internal.FontCache.Util' threw an exception. 
---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.

   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
    at System.Uri..ctor(String uriString, UriKind uriKind)
    at MS.Internal.FontCache.Util..cctor()

 --- End of inner exception stack trace ---

   at MS.Internal.FontCache.Util.get_Dpi()
   at System.Windows.SystemFonts.ConvertFontHeight(Int32 height)
   at System.Windows.Documents.TextElement..cctor()

   --- End of inner exception stack trace ---

   at System.Windows.FrameworkElement..cctor()

   --- End of inner exception stack trace ---

   at System.Windows.Window..cctor()

   --- End of inner exception stack trace ---

   at System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadBamlStreamWithSyncInfo(Stream stream, ParserContext pc)
   at System.Windows.Application.LoadComponent(Uri resourceLocator, Boolean bSkipJournaledProperties)
   at System.Windows.Application.DoStartup()
   at System.Windows.Application.<.ctor>b__1(Object unused)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
user380689
  • 1,766
  • 4
  • 26
  • 39
  • possible duplicate of [WPF window throws TypeInitializationException at start up](http://stackoverflow.com/questions/10094197/wpf-window-throws-typeinitializationexception-at-start-up). I know this question is older, but the other one has better answers – David Gardiner Jul 21 '14 at 07:28

2 Answers2

1

It looks like it's having a problem at this point:

---> System.TypeInitializationException: The type initializer for 'MS.Internal.FontCache.Util' threw an exception. 
---> System.UriFormatException: Invalid URI: The format of the URI could not be determined.

Seeing that the issue is not consistent between machines and there's mention of fonts, is it possible that you're referencing a font that isn't installed on this particular machine?

Rich
  • 36,270
  • 31
  • 115
  • 154
  • The app is using the default WPF font "Segoe UI". I believe it should pick some alternative font if thats not installed? Anyway I think your on the right track. Thanks. – user380689 Feb 23 '11 at 22:31
0

The problem is due to the WinDir environment variable getting messed up, which is used in the static initializer for internal Microsoft class FontCache.Util. This could be caused by a very long PATH environment variable, as documented here: https://superuser.com/questions/237268/missing-environment-variables-in-windows-7.

(FontCache.Util: http://referencesource.microsoft.com/#PresentationCore/Core/CSharp/MS/Internal/FontCache/FontCacheUtil.cs).

Community
  • 1
  • 1
Joshua Marble
  • 540
  • 3
  • 9