Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

wpf

xaml

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);
      else
        win = new ReportParametersWindow(rpt.FriendlyName, (container.ParametersWindow as ReportParametersWindow).Controls, canOverWrite);

      win.ShowDialog();

And the XAML for the window:

<Window xmlns:my="clr-namespace:MHA.Modules.Core.Controls;assembly=MHA.Modules.Core"  
    x:Class="MHA.Modules.Reports.Views.ReportParametersWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Parameters" Height="500" Width="600" MinWidth="500" MaxHeight="500" 
    Icon="/MHA.Modules.Reports;component/Images/Parameters.ico" SizeToContent="WidthAndHeight" 
    WindowStartupLocation="CenterScreen"
    xmlns:odc="clr-namespace:Odyssey.Controls;assembly=Odyssey" Closed="Window_Closed">

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

        <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>
            </StackPanel>
        </Button>
    </Grid>
</Grid>

Does anyone have suggestions?

like image 275
Chrisjan Lodewyks Avatar asked Oct 11 '12 06:10

Chrisjan Lodewyks


3 Answers

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.

like image 199
Chrisjan Lodewyks Avatar answered Nov 12 '22 14:11

Chrisjan Lodewyks


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

like image 22
Kevin Avatar answered Nov 12 '22 15:11

Kevin


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.

like image 11
user2125523 Avatar answered Nov 12 '22 15:11

user2125523