Why am I getting a XamlParseException?

Nicholas Piazza 466 Reputation points

I'm getting

when I run the application. I have put my image files in an Images folder in the same folder as the project file. The XAML designer seems to locate them fine as shown in

but the exception is being reported on the following MainWindow.Xaml line

<ribbon:RibbonButton SmallImageSource="Images\SmallIcon.png" />

Why am I getting this exception and how do I correct it?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,372 questions
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
8,203 questions
{count} votes

Accepted answer
  1. Michael Taylor 41,631 Reputation points

    The error indicates it isn't finding the images. Your XAML is relying on the image actually being deployed on disk like it is when you're in the designer. This is not going to be true unless you mark the image file as content (using Build Action property of the file in Solution Explorer). That would then cause the file structure to be available at runtime. But that is non-standard. Normally you would embed the image as a resource instead. You can read about how to do that here. In either case you need to modify your XAML to use the correct image source URL and you need to ensure the image is available (either on disk or as a resource) otherwise you get the error you're seeing now.

0 additional answers

Sort by: Most helpful