Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type reference cannot find public type named

Tags:

c#

wpf

xaml

I am getting error like "Type reference cannot find public type named 'Sign'" in xaml. how can i resolve it. the Sign class is in the same assembly.

<DataTemplate DataType="{x:Type local:Sign}">
    <Expander Padding="4"
              IsExpanded="{Binding RelativeSource={
                    RelativeSource Mode=FindAncestor, AncestorType={
                       x:Type ListBoxItem}}, Path=IsSelected}">
        <Expander.Header>
            <TextBlock Text="{Binding Name}" ... />
        </Expander.Header>
        <DockPanel LastChildFill="True">
            <Border DockPanel.Dock="Left" CornerRadius="16" BorderBrush="WhiteSmoke" Background="AliceBlue" BorderThickness="5" HorizontalAlignment="Center" VerticalAlignment="Center">
                <Image Source="{Binding Icon}" Width="90" Height="90" Stretch="Fill" />
            </Border>
            ...
        </DockPanel>                
    </Expander>

like image 631
Tanya Avatar asked May 04 '12 05:05

Tanya


3 Answers

If the type resides in the same assembly as the XAML you are modifying, omit the assembly segment of the clr-namespace when you import the namespace.

DO

xmlns:local="clr-namespace:NamespaceContainingSignClass"

DO NOT

xmlns:local="clr-namespace:NamespaceContainingSignClass;assembly=AssemblyContainingSignClassAndXAML"
like image 117
smelch Avatar answered Nov 15 '22 20:11

smelch


For those in my boat who weren't helped by the top 1,00 results for this error on Google....in my case it was the precise opposite of the advice from smelch: i had to ADD the assembly info on the end of my xmlns declaration. Likely because of my particular circumstances, i guess - my datatemplate was in a stand-alone resourcedictionary xaml file. Not sure. I just know it didn't work until i added the assembly info, so for those floundering out there give that a whack and see if it works. i'm not inclined to dive into why, it just did.

like image 45
tntwyckoff Avatar answered Nov 15 '22 19:11

tntwyckoff


  1. Check if the root tag of the xaml file has the namespace with class Sign mapped to local alias: xmlns:local="clr-namespace:NamespaceContainingSignClass"
  2. Check whether class Sign is marked public
  3. Check whether class Sign has parameterless constructor
like image 31
EvAlex Avatar answered Nov 15 '22 20:11

EvAlex