4

我正在寻找调试 XAML 错误的一般做法/方法。通常 C# 错误很容易查找并且足够具体以查找相关信息。但是,XAML 似乎只是抛出一个通用XAML Parsing failed错误:

在此处输入图像描述

我正在寻找一种通用的方法来处理这些错误并缩小可能对抛出的错误有用的文件、行号或任何其他信息。

4

3 回答 3

3

这是我用来在不清楚时识别导致 XAML 错误的文件的一种简洁方法......

用资源字典一一打开所有 XAML 文件,在打开的根元素后添加一个空格。再次在调试器中运行,直到出现故障点,当行号增加一时,您已找到该文件。

没有人可以为这种行为辩护。我只能想象框架资源加载方法是用流调用的,所以不知道它正在读取的文件的名称是什么,只是其中的位置。

它需要改进。调用资源加载方法的框架部分应该发出调试消息或在某种上下文中传递名称,以便框架的较低部分可以发出合理的错误消息。

于 2012-10-20T18:59:02.230 回答
1

Note: I plan on expanding this as I move along and learn more. If you would like to contribute to this answer, I will change this to CW and in the mean time feel free to make any changes you seem fit

Smaller changes == Smaller scoped errors

In general, just as @DenDelimarsky has stated, making small changes and running/debugging the code is a good start. That will, most of the time, narrow down the scope of the error to just the areas that you've been working in.

However here are a few other tips that you can use to narrow down the issues:

Search for the Class:

Your specific message for exception e states this:

Failed to assign to property 'Windows.UI.XAML.ResourceDictionary.Source' (emphasis added)

This means that the class ResourceDicionary is having complications assigning the property Source. Perform a search first within the scope of the files you've edited and then, if no errors are found, within the entire solution for this class and look for any errors that may be present.

于 2012-10-15T21:00:30.910 回答
0

实际上,您所看到的是处理 XAML 错误的正常方法。不仅如此,您实际上还看到了 StandardStyles 之外的问题。此外,如果您遵循常规调试实践并在修改 XAML 后经常进行调试,通常很容易缩小问题范围。

于 2012-10-15T20:16:23.137 回答