Capturing XAML code resolution exceptions in a WPF application

Source: Internet
Author: User
Tags exception handling visual studio

Because XAML code in a WPF application is handled most of the time by a run-time load. such as DynamicResource, but the XAML code parser usually throws an exception called Xamlparseexception in the process of compiling or running. However, the xamlparseexception exception provided is very simple or inaccurate. At this point we are going to get more exception information by using the workaround method:

We know that XAML code in a WPF application is parsed in the InitializeComponent method. This method is usually in the constructor of the Window object. So, we use. NET's exception mechanism to invoke method InitializeComponent:

The following are the referenced contents:
1 public partial class Window1:System.Windows.Window
2 {
3 Public Window1 ()
4 {
5 Try
6 {
7 InitializeComponent ();
8}
9 catch (Exception ex)
10 {
11//exception handling (innerexceptions)
12}
13}
14}

So invoking InitializeComponent can help us get more accurate exception information when debugging.

In addition to the above exception capture mechanism, another scenario is to take advantage of the Visual Studio Exception dialog box. Exception under menu debugging (Debug) (Exception ...). dialog box, add System.Markup.XamlParseException to the Exception capture list by adding a button to the lower right. and select the Thrown check box. So you can get more information about xamlparseexception.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.