C# 创建格式错误的Xaml文档,该文档引发System.Windows.Markup.XamlParseException

C# 创建格式错误的Xaml文档,该文档引发System.Windows.Markup.XamlParseException,c#,wpf,xaml,exception-handling,xamlparseexception,C#,Wpf,Xaml,Exception Handling,Xamlparseexception,我在德国有一个用户(作为众多用户中唯一的一个)在运行我的应用程序时得到一个XamlParseException(请参见下面的stacktrace) 不幸的是,这个异常是出了名的缺乏信息性,所以我不知道是什么导致了它,我无法复制它 然而,我想我应该能够抓住它,并获得一些额外的信息 我的问题是-我如何测试它?创建一个格式错误的Xaml文档似乎很简单,但我无法创建一个Visual Studio在编译时无法捕获的文档 有人能帮我创建一个Xaml文件吗?哪个文件会抛出异常,这样我就可以尝试捕获并处理它了

我在德国有一个用户(作为众多用户中唯一的一个)在运行我的应用程序时得到一个XamlParseException(请参见下面的stacktrace)

不幸的是,这个异常是出了名的缺乏信息性,所以我不知道是什么导致了它,我无法复制它

然而,我想我应该能够抓住它,并获得一些额外的信息

我的问题是-我如何测试它?创建一个格式错误的Xaml文档似乎很简单,但我无法创建一个Visual Studio在编译时无法捕获的文档

有人能帮我创建一个Xaml文件吗?哪个文件会抛出异常,这样我就可以尝试捕获并处理它了

<exception type="System.Windows.Markup.XamlParseException">
<message>Vorgang hat einen ungültigen Status verursacht.</message>
<stacktrace>
bei System.Windows.Markup.XamlReader.RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
bei System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter)
bei System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
bei System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField)
bei System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren)
bei System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate)
bei System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container)
bei System.Windows.FrameworkElement.ApplyTemplate()
bei System.Windows.FrameworkElement.MeasureCore(Size availableSize)

这是一个非常重要的问题。
bei System.Windows.Markup.XamlReader.RewrapException(异常e、IXamlLineInfo、Uri baseUri)
bei System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader,XamlObjectWriter currentWriter)
bei System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter)
bei System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject容器、IComponentConnector componentConnector、IStyleConnector styleConnector、列表'1 affectedChildren、unmonfield'1 templatedNonFeChildrenField)
bei System.Windows.FrameworkTemplate.LoadContent(DependencyObject容器,列表'1 affectedChildren)
bei System.Windows.StyleHelper.ApplyTemplateContent(不常见字段`1数据字段,DependencyObject容器,FrameworkElementFactory templateRoot,Int32 lastChildIndex,HybridDictionary childIndexFromChildID,FrameworkTemplate FrameworkTemplate)
bei System.Windows.FrameworkTemplate.ApplyTemplateContent(不常见字段`1 templateDataField,FrameworkElement容器)
bei System.Windows.FrameworkElement.ApplyTemplate()
bei System.Windows.FrameworkElement.MeasureCore(可用大小Size)

使用任何xaml并删除其中一些重要的内容,如引号、尖括号、斜杠等。例如
对我来说可靠的方法是在xaml中创建的对象的构造函数中引发异常。例如,在某些
用户控件中
。您还可以检查
XamlParseException
中的
InnerException
属性(并打印其堆栈跟踪)。正如@Ale所指出的,原因可能不是XAML本身,而是XAML中引用的构造函数中的代码:自定义控件、转换器、,甚至可以查看模型或在XAML中添加到资源字典中的任何内容。我建议你好好看看那些。