Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: 'Cannot create unknown type '{clr-namespace:NameSpace.Properties}Settings'.'

I define my settings and styles in a ResourceDictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:properties="clr-namespace:Kavand.UI.Properties">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary>
            <properties:Settings x:Key="settings" />
        </ResourceDictionary>
    </ResourceDictionary.MergedDictionaries>
    <Style x:Key="PopupMenu_StackPanel">
        <Setter Property="TextBlock.FontSize" Value="{Binding Source={StaticResource settings}, Path=Default.Font_Menu_Size}" />
        <Setter Property="TextBlock.FontFamily" Value="{Binding Source={StaticResource settings}, Path=Default.Font_Menu_Family}" />
        <Setter Property="TextBlock.FontWeight" Value="{Binding Source={StaticResource settings}, Path=Default.Font_Menu_Weight}" />
        <Style.Resources>
            <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource KavandMenuItem}">
                <Style.Triggers>
                    <Trigger Property="IsChecked" Value="true">
                        <Setter Property="IsEnabled" Value="false" />
                    </Trigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsChecked" Value="True" />
                            <Condition Property="IsHighlighted" Value="True" />
                        </MultiTrigger.Conditions>
                        <Setter Property="Foreground" Value="{DynamicResource K_Brush_Gray}" />
                    </MultiTrigger>
                </Style.Triggers>
            </Style>
        </Style.Resources>
    </Style>
</ResourceDictionary>

When I run my application, I get the error:

'Cannot create unknown type '{clr-namespace:Kavand.UI.Properties}Settings'.' Line number '6' and line position '14'.

like image 676
amiry jd Avatar asked May 27 '11 19:05

amiry jd


4 Answers

I had set the file's "Build Action" property to "Resource". When I changed it to "Page" the problem was resolved.

like image 56
amiry jd Avatar answered Nov 18 '22 15:11

amiry jd


Keep your "Build Action" property to "Resource" and just change this row:

xmlns:properties="clr-namespace:Kavand.UI.Properties"

with this:

xmlns:properties="clr-namespace:Kavand.UI.Properties;assembly=Kavand.UI"
like image 36
Vladimir Trifonov Avatar answered Nov 18 '22 15:11

Vladimir Trifonov


Just posting another potential solution, because i just recently stumbled over this exception.

It could be that your referenced class-cefinition (in your case Kavand.UI.Properties.Settings) does not use public-access-modifier.

So in my case i could solve this problem by writing public before the class definition.

like image 4
lukas hoellriegl Avatar answered Nov 18 '22 14:11

lukas hoellriegl


As a variation on other answers & comments, this worked for me:

  • Set the file's "Build Action" property to "Page".

  • Build (problem gone - but...)

  • Set the file's "Build Action" property to "Resource".

  • Build

  • Problem still gone!

Seems like a VS bug to me.

like image 3
StayOnTarget Avatar answered Nov 18 '22 16:11

StayOnTarget