'Provide value on 'System.Windows.Baml2006.TypeConverterMarkupExtension' threw an exception.'

The exception in the title is thrown when I open a window in WPF, the strange thing is that this does not happen on my Windows 7 development machine nor does it happen when it is deployed on Windows 7.

I only get this error on Windows XP, and only the second time that I open the window.

Here is the code to open the window:

ReportParametersWindow win = null;

      bool canOverWrite = _shownReports.Contains(rpt.FriendlyName);

      if (!(canOverWrite))
        win = new ReportParametersWindow(rpt.FriendlyName, rpt.ReportParameters, canOverWrite);
        win = new ReportParametersWindow(rpt.FriendlyName, (container.ParametersWindow as ReportParametersWindow).Controls, canOverWrite);


And the XAML for the window:

<Window xmlns:my="clr-namespace:MHA.Modules.Core.Controls;assembly=MHA.Modules.Core"  
    Title="Parameters" Height="500" Width="600" MinWidth="500" MaxHeight="500" 
    Icon="/MHA.Modules.Reports;component/Images/Parameters.ico" SizeToContent="WidthAndHeight" 
    xmlns:odc="clr-namespace:Odyssey.Controls;assembly=Odyssey" Closed="Window_Closed">

        <RowDefinition Height="*"/>
        <RowDefinition Height="40"/>
    <ScrollViewer Grid.Row="0" Name="ScrollViewer1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" CanContentScroll="True">
        <StackPanel Name="ParameterStack">
            <my:LocationCtl Text="Parameters for report - " Name="loc"/>
    <Grid Grid.Row="1">

        <CheckBox ToolTip="This will replace the first report of the same type that was shown." Name="chkOverwrite" Content="Overwrite old" VerticalAlignment="Center" Margin="5,0"></CheckBox>

        <Button Grid.Column="2" HorizontalAlignment="Right" Margin="5,0" Height="30" Style="{StaticResource DionysusButton}" Width="100" IsDefault="True" Click="Button_Click">
            <StackPanel Orientation="Horizontal">
                <Image Source="/MHA.Modules.Reports;component/Images/Success.png"></Image>
                <TextBlock Margin="5,0" Text="Accept" VerticalAlignment="Center"></TextBlock>

Does anyone have suggestions?

The solution is quite a weird one but I have it figured out.

I realized that the error was occurring on the InitializeComponent() of the window, I then added a try catch to the constructor and showed the InnerException of the Exception.

The error that I received is "Image format not recognized".

I have no idea why this happens only on XP and the second time that the window is shown but by replacing my .ico with a .png the problem was resolved.

Hope this helps someone.

I just ran into this issue as well... I know this is old, but what I had to end up doing was set the images to Resource, and Copy Always... only by browsing my /bin/Debug folder did I realize that the images were not at a valid path location

This problem can also occur if the required image is not available at the specified location. So Check the inner exception and add any image that might have been missed or misspelled.

I got this error because my Command Binding of a Button was wrong:

<Button Command="MyCommand" />

instead of

<Button Command="{Binding MyCommand}" />

You Should first Import Image to your project Solution Explorer - Show All

then Right Click on the image and select Include

Now Use end

  • Try to comment out as much code as you can and still throw the exception. The idea is to find the single thing that is essential to cause this exception to be thrown.
  • Was getting this as well, very strange. I can add an image with an icon, but if I set the image source to an icon with a style trigger, i get this problem...
  • This is strange. I changed my project name, and my assembly name. Then I obtained the msg that the IndexConverter class doesn't exist in my namespace (error in XAML) - but everything was fine. Then I had found that post. It helped. The problem was with the program icon in the other file (that didn't prompt me with error)... Thanks! Have a nice day for that:D
  • Thanks Nickon, worked for me. My icons had the assembly name hardcoded in the path, I changed it to relative to the application and it solved the issue.
  • I misspelled Resources: Icon="./Resourses/cmd_IDI_APPICON.ico". That hurts! Seems like it's all about icons.
  • Instead of adding try..catch, to see inner exception you can go to Debug>Windows>Locals
  • I set mine to content instead of Resource
  • That would probably work as well, so long as the images and their locations are properly outputted to the Debug and/or Release folders it should be good
  • For me I had to set both Copy = Always and Build Action = Content to get it to work. :/ (was setting a PNG file as an ImageBrush inside a Rectangle) Thanks guys.
  • Indeed, Copy = Always did the trick, Build Action was already on Content.
  • This solution worked for me. Apparently I didn't have the image included.
  • +1 - I ran into this specifically because my icon file had not been marked as a "Resource" -- it's an easy mistake to make, and yet the error message is not very clear. Just said it cannot locate resource 'icon.ico'. Hope this helps someone else.