System.Windows.Markup.XamlParseException occurred. Microsoft visual studio community 2017

0

Please can someone be of help. I encountered this exception below, while trying to compile an XAML code.

System.Windows.Markup.XamlParseException occurred HResult=0x80131501 Message='Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.' Line number '28' and line position '22'. Source=PresentationFramework StackTrace: at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri) at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri) at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator) at XAMLImage.MainWindow.InitializeComponent() in c:\users\mypc\documents\visual studio 2017\Projects\XAMLImage\XAMLImage\MainWindow.xaml:line 1

Inner Exception 1: IOException: Cannot locate resource 'images/tahoe_01.jpg'.

The exception occurred at "InitializeComponent()" of the c# partial class of the code behind. Below is the c# partial class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace XAMLImage
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

Below is the XAML code

<Window x:Class="XAMLImage.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:XAMLImage"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="604">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height = "1*"/>
            <RowDefinition Height = "1*"/>
        </Grid.RowDefinitions>

        <StackPanel Orientation="Horizontal">
            <Image Width = "200" VerticalAlignment = "Top" Margin = "30"/>
            <Image Width = "200" Source = "Images\flow5.gif" 
            VerticalAlignment = "Top" Margin = "30" Opacity = "0.5"/>
        </StackPanel>

        <StackPanel Grid.Row = "1">
            <Ellipse Height = "100" 
            Width = "200" 
            HorizontalAlignment = "Center" 
            Margin = "30">

                <Ellipse.Fill>
                    <ImageBrush ImageSource = "Images\bubble.png" />
                </Ellipse.Fill>

            </Ellipse>



        </StackPanel>
    </Grid>
</Window>

There is a blue squiggly line under the Source URL of the Image and ImageSource URL of the ImageBrush elements. I hover my mouse over them, and intellisense says "could not find file 'c:\Program Files(x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\images%5Cmyfilename.gif'"(one of the files is a gif, and the other is a png). I thought these was an unsual path for the file to be located, but I went on and created the URLs on that path, but expection, still throwing.

Please can someone be of help. Am using Microsoft visual studio community 2017

Cheers

c#
xaml
asked on Stack Overflow May 18, 2017 by Evan • edited Jun 20, 2020 by Community

1 Answer

0

With the help of a good person in these community, I managed to solve the problem. You need the images folder to be part of the project. The images folder needs to be in the same folder as the code files. These you can achieve by copying and pasting the images folder into the same folder as the code files, in windows file explorer. After these I was able to see the images on my designer. But the project still doesn't know about the images(at least during compile/run time). For the project to know about the images folder, it needs to be included into the project. These you can achieve by, in Visual Studio, go to solution explorer, upper bar there's an icon button for 'Show All Files'. After clicking, you should see the folder, but with low opacity. Right click on it and then 'Include In Project'.

answered on Stack Overflow May 21, 2017 by Evan

User contributions licensed under CC BY-SA 3.0