Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XamlParseException无效URI:无法确定URI的格式_C#_Wpf_Exception - Fatal编程技术网

C# XamlParseException无效URI:无法确定URI的格式

C# XamlParseException无效URI:无法确定URI的格式,c#,wpf,exception,C#,Wpf,Exception,我在一台电脑上的WPF应用程序中遇到了这个异常,在六台其他电脑上运行正常。以下是完整的异常跟踪: System.Windows.Markup.XamlParseException: The type initializer for 'System.Windows.Window' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Windows.Fram

我在一台电脑上的WPF应用程序中遇到了这个异常,在六台其他电脑上运行正常。以下是完整的异常跟踪:

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)
System.Windows.Markup.XamlParseException:“System.Windows.Window”的类型初始值设定项引发异常。
--->System.TypeInitializationException:“System.Windows.FrameworkElement”的类型初始值设定项引发异常。
--->System.TypeInitializationException:“System.Windows.Documents.TextElement”的类型初始值设定项引发异常。
--->System.TypeInitializationException:“MS.Internal.FontCache.Util”的类型初始值设定项引发异常。
--->System.UriFormatException:无效的URI:无法确定URI的格式。
在System.Uri.CreateThis(字符串Uri、布尔顿特斯卡普、UriKind)
在System.Uri..ctor(字符串uriString,UriKind-UriKind)
在MS.Internal.FontCache.Util..cctor()处
---内部异常堆栈跟踪的结束---
在MS.Internal.FontCache.Util.get_Dpi()处
位于System.Windows.SystemFonts.ConvertFontHeight(Int32高度)
在System.Windows.Documents.TextElement..cctor()中
---内部异常堆栈跟踪的结束---
在System.Windows.FrameworkElement..cctor()中
---内部异常堆栈跟踪的结束---
在System.Windows.Window..cctor()中
---内部异常堆栈跟踪的结束---
位于System.Windows.Markup.XamlReader.RewrapException(异常e、IXamlLineInfo、Uri baseUri)
在System.Windows.Markup.WpfXamlLoader.Load(XamlReader XamlReader、IXamlObjectWriterFactory writerFactory、Boolean skipJournaledProperties、Object rootObject、XamlObjectWriterSettings设置、Uri baseUri)
位于System.Windows.Markup.wpfxamloader.LoadBaml(XamlReader XamlReader、Boolean skipJournaledProperties、Object rootObject、XamlAccessLevel accessLevel、Uri baseUri)
位于System.Windows.Markup.XamlReader.LoadBaml(Stream-Stream,ParserContext-ParserContext,Object-parent,Boolean-closeStream)
在System.Windows.Application.LoadBamlStreamWithSyncInfo(流,ParserContext pc)
位于System.Windows.Application.LoadComponent(Uri resourceLocator,布尔bSkipJournaledProperties)
在System.Windows.Application.DoStartup()中
在System.Windows.Application.b__1(未使用的对象)
位于System.Windows.Threading.ExceptionWrapper.InternalRealCall(委托回调、对象参数、Int32 numArgs)
位于MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(对象源、委托方法、对象参数、Int32 numArgs、委托catchHandler)

此时它似乎有问题:

---> 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.

看到机器之间的问题不一致,并且提到了字体,您是否引用了未安装在此特定机器上的字体?

问题是由于WinDir环境变量出错,该变量在内部Microsoft类FontCache.Util的静态初始值设定项中使用。这可能是由一个很长的PATH环境变量引起的,如下所述:


(FontCache.Util:)。

应用程序使用默认WPF字体“Segoe UI”。我认为它应该选择一些替代字体,如果没有安装?无论如何,我认为你的计划是正确的。谢谢。可能是的副本。我知道这个问题比较老,但另一个有更好的答案