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

4

34

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'.

Tribune answered 27/5, 2011 at 19:17 Comment(2)
Is it a compile error or a runtime error? Does removing the first three setters allow the application to run?Unknown
It is a runtime error, no, just when I remove section that contains definition, application will be compiledTribune
T
55

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

Tribune answered 28/5, 2011 at 8:21 Comment(1)
Waaat? This worked for me too. But the documentation explicitly says to make sure your resource dictionaries have "Resource" build actions.Malony
M
50

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"
Madame answered 29/4, 2013 at 13:57 Comment(2)
I set the build action back to Resource and it worked even without the namespace change. Gaaah! This problem is so fickle. What is up with Visual Studio?Malony
Anyone knows when to use Resource and when to use Page? In some other articles using Resource was recommended to solve other mysterious behaviour of user control libraries.Pye
C
4

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.

Chromatism answered 25/4, 2018 at 12:22 Comment(1)
Thank you! This was the problem I had that lead me to this question. My class was "internal". Changing it to "public" solved my issue. +1Reasoned
S
3

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.

Susian answered 17/2, 2020 at 19:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.