XamlParseException class

Applies to Windows and Windows Phone

The exception that is thrown when an error occurs while parsing XAML.


public class XamlParseException : Exception


The XamlParseException class has these types of members:


The XamlParseException class has these constructors.

XamlParseException() Initializes a new instance of the XamlParseException class.
XamlParseException(String) Initializes a new instance of the XamlParseException class with a specified error message.
XamlParseException(String,Exception) Initializes a new instance of the XamlParseException class with a specified error message and a reference to the inner exception that is the cause of this exception.



The XamlParseException class has these events.

SerializeObjectState (Inherited from Exception)



The XamlParseException class has these methods. It also inherits methods from the Object class.

GetBaseException (Inherited from Exception)
GetObjectData (Inherited from Exception)
GetType (Inherited from Exception)
ToString (Inherited from Exception)



The XamlParseException class has these properties.

PropertyAccess typeDescription


Read-only (Inherited from Exception)


Read/write (Inherited from Exception)


Read-only (Inherited from Exception)


Read-only (Inherited from Exception)


Read-only (Inherited from Exception)


Read/write (Inherited from Exception)


Read-only (Inherited from Exception)


Read-only (Inherited from Exception)



To learn more about the reason why the exception was thrown, look at the Message value. XamlParseException is implemented so that the Message string typically provides this information:

  • A short description of the parsing condition that failed.
  • The name of an element or attribute that caused the condition.
  • A line number and character position on that line where the condition was encountered in the original XAML source file.

Most of the time any problems with XAML are detectable at design-time, but it's still possible for problems to occur that would only be known at run-time, in which case you get a XamlParseException.

XamlParseException is thrown only by the framework-implemented XAML parser that performs the XAML parsing and loading for Windows Runtime apps. The exception can also originate from user code in run-time calls to APIs that hook up the parser to load XAML from within a running app (for example, calls to XamlReader.Load).

You generally don't throw XamlParseException from your own code. However, handling for the exception is sometimes necessary. An UnhandledException event handler at the app level is one way to handle a run-time XamlParseException. Another technique is to wrap calls to APIs that might throw the exception (like XamlReader.Load) in a try-catch block and catch the exception there. Whether to suppress exceptions or let them surface to user code depends on how you design your application for purposes of loading XAML, and the trust level that you assign to the XAML your application loads.

For pages of an app in its navigation structure, if the XamlParseException is thrown, it is usually in the context of the InitializeComponent call made by your page class. Initialization exceptions are usually caught at design time, but there are occasional cases where these can still happen. For example, API design problems within your custom types that you reference from your XAML can sometimes show up as exceptions that the design time environment didn't catch.

XamlParseException is only thrown if your app is written using C# or Microsoft Visual Basic (Visual C++ component extensions (C++/CX) uses Platform::COMException instead for any XAML parsing error, with specifics in the message string).

Migration note

The XamlParseException class in other frameworks such as Microsoft Silverlight has specific properties beyond the Exception base API. For example, there is a BaseUri property and discrete properties for LineNumber and LinePosition. The Windows Runtime version of XamlParseException doesn't have these properties, but all the information you typically need to correct the exception at design time or process the exception at app run-time can be obtained from the Message string.


Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]





See also

XAML overview
Exception handling for Windows Store apps in C# or Visual Basic
Cross-reference: Standard exceptions and error codes



© 2015 Microsoft