XamlReader and “XamlParseException occurred Message=Unknown parser error: Scanner 2147500037”

XamlReader is a great tool for loading arbitrary XAML in your application. There are a number of rules you need to follow though (not all XAML that would otherwise load into an app would load with it) – some of it is straightforward and the parser will be nice enough to tell you exactly what the issue is (such as when you specify x:Class on a UserControl), but on other issues, the parser will just barf and throw an exception.

I recently hit one of these places and after a little help, was able to figure out the issue.

In my case, the parser died because, when loading XAML dynamically, some of the rules of clr-namespace prefixes (these are the guys that help you load CLR objects in XAML) that govern dynamically loaded XAML are different.

Generally, when the XAML belongs to an assembly, you do not need to specify the name of the assembly name in the XAML files – the infrastructure will deduce it by itself.  However, if you use XamlReader, you need to specify the assembly name for all namespaces.

Note that this problem is mostly solved on Windows 8 for example, by having the XAML processor just rely on namespaces and not need the actual assembly names.

This entry was posted in Dev, WindowsPhone. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s