Why am I getting a XamlParseException?

Nicholas Piazza 536 Reputation points
2022-11-03T14:52:53.607+00:00

I'm getting
254912-xamlparseexception.png

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
254913-mainwindowimages.png

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,710 questions
C#
C#
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.
10,648 questions
{count} votes

Accepted answer
  1. Michael Taylor 51,346 Reputation points
    2022-11-03T18:45:00.887+00:00

    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