简体   繁体   English

类型引用找不到命名类型……不是因为缺少程序集名称

[英]Type reference cannot find type named… NOT because of missing assembly name

Just to get this clear ahead of time, I am well aware of the abundance of questions and answers regarding this error that are due to missing assembly names in the declaration, that is not the case here. 只是为了提前弄清楚这一点,我很清楚关于此错误的大量问题和答案,这是由于声明中缺少程序集名称而导致的,在此情况并非如此。

I have been seeing some pretty serious instability in the past couple days with code that would seemingly by itself stop compiling throwing errors that were untrue, then magically start working again after closing then re-opening VS, have also had my custom controls stop showing up in the designer and spit out phantom errors in the ctor() then fix themselves and dependency properties in my controls go missing from the VS properties explorer but still be accessible from XAML.... Im wondering if possibly im surfacing some sort of bug in VS, it's happened before when I discovered bugs in VS causing my g.cs files to break... 在过去的几天里,我一直看到一些非常不稳定的代码,它们似乎会停止编译不正确的抛出错误,然后在关闭然后重新打开VS后神奇地重新开始工作,还让我的自定义控件停止显示在设计器中并在ctor()中吐出幻影错误,然后修复自身,并且控件中的依赖项属性从VS属性资源管理器中丢失,但仍可以从XAML访问。...我想知道是否可能会出现一些bug, VS,这是在我发现VS中的错误导致g.cs文件损坏之前发生的...

Severity Code Description Project File Line Suppression State Error Type reference cannot find type named '{clr-namespace:ODIF;assembly=PluginInterface}Global'. 严重性代码说明项目文件行抑制状态错误类型参考找不到名为“ {clr-namespace:ODIF; assembly = PluginInterface}全局”的类型。 CustomControls_WinX86 xxxxxxxxx\\CustomControls_WinX86\\ChannelBoxMenu.xaml 17 CustomControls_WinX86 xxxxxxxxx \\ CustomControls_WinX86 \\ ChannelBoxMenu.xaml 17

Complete XAML for my user control: 为我的用户控件完成XAML:

UserControl x:Name="ChannelBoxMenuControl" x:Class="CustomControls_WinX86.ChannelBoxMenu"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CustomControls_WinX86"
             xmlns:ODIF="clr-namespace:ODIF;assembly=PluginInterface"
             mc:Ignorable="d" 
             d:DesignHeight="100" d:DesignWidth="250">
    <Grid>
        <Menu x:Name="menu">
            <MenuItem x:Name="menuItem" BorderThickness="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Template="{DynamicResource MarginlessMenuItem}" Width="{Binding ActualWidth, ElementName=menu, Mode=OneWay}" Height="{Binding ActualHeight, ElementName=menu, Mode=OneWay}" >
                <MenuItem.Header>
                    <local:ChannelBox Width="{Binding ActualWidth, ElementName=menuItem, Mode=OneWay}" Height="{Binding ActualHeight, ElementName=menuItem, Mode=OneWay}" Channel="{Binding SelectedChannel, ElementName=ChannelBoxMenuControl}"/>
                </MenuItem.Header>
                <MenuItem.ItemTemplate>
                    <HierarchicalDataTemplate ItemsSource="{Binding Source={x:Static  ODIF:Global.ConnectedDevices}, Mode=OneWay}"><!--THIS IS WHERE THE ERROR IS THROWN-->
                        <StackPanel HorizontalAlignment="Left" Orientation="Horizontal">
                            <Image Source="{Binding StatusIcon}" Width="16" Height="16">
                                <Image.Style>
                                    <Style TargetType="{x:Type Image}">
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Icon}" Value="{x:Null}">
                                                <Setter Property="Visibility" Value="Collapsed" />
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Image.Style>
                            </Image>
                            <TextBlock Text="{Binding DeviceName}"/>
                        </StackPanel>
                    </HierarchicalDataTemplate>
                </MenuItem.ItemTemplate>
            </MenuItem>
        </Menu>
    </Grid>
</UserControl>

And the relevant code from my referenced assembly: 以及我引用的程序集中的相关代码:

namespace ODIF
{
    public static class Global
    {
        internal static GlobalStore Store = new GlobalStore();
        public static AsyncObservableCollection<InputDevice> ConnectedDevices
        {
            get
            {
                return Store.inputDevices;
            }
        }
    }
    internal class GlobalStore
    {
        internal AsyncObservableCollection<InputDevice> inputDevices;
    }
}

Also worth noting that when I begin typing in the path for the HierarchicalDataTemplate ItemsSource, intellisense picks up the path ODIF:Global.ConnectedDevices just fine and auto completes it, but then throws error that it cannot find it.... 同样值得注意的是,当我开始输入HierarchicalDataTemplate ItemsSource的路径时,intellisense会选择路径ODIF:Global.ConnectedDevices并自动完成它,但是会引发找不到它的错误。

Not really an explanation as to why the above won't work, as best I can tell it should. 尽我所能告诉我,这并不是关于为什么上述方法行不通的真正解释。 But a workaround for me if anybody comes across the same issue is to create a static property in the UserControl's class that references the static property in the other assembly: 但是,如果有人遇到相同的问题,对我来说,一种解决方法是在UserControl的类中创建一个静态属性,该类引用另一个程序集中的静态属性:

Added to ChannelBoxMenu : UserControl 添加到ChannelBoxMenu:UserControl

    public static AsyncObservableCollection<ODIF.InputDevice> ConnectedDevices
    {
        get
        {
            return Global.ConnectedDevices;
        }
    }

And modified my binding to read: 并将我的绑定修改为:

ItemsSource="{Binding ConnectedDevices, ElementName=ChannelBoxMenuControl}

It's not as clean as the direct reference, but it has the benefit of working. 它不像直接参考那样干净,但是它具有工作的好处。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型引用找不到命名的公共类型 - Type reference cannot find public type named 类型引用找不到名为命令的类型 - Type reference cannot find type named Commands C#找不到类-找不到类型或名称空间名称“ GradeBook”(您是否缺少using指令或程序集引用?) - C# cannot find class - The type or namespace name 'GradeBook' could not be found (are you missing a using directive or an assembly reference?) 类型或名称空间名称在名称空间中不存在“是否缺少程序集引用?” - The type or namespace name does not exist in the namespace ''are you missing an assembly reference ?" 找不到类型或名称空间名称(缺少使用指令或程序集引用吗?) - Type or namespace name could not be found (missing using directive or assembly reference?) 命名空间中不存在类型或命名空间名称(您是否缺少程序集引用?) - The type or namespace name does not exist in the namespace (are you missing an assembly reference?) 找不到类型或命名空间(您是否缺少using指令或程序集引用?) - The type or namespace cannot be found (are you missing a using directive or an assembly reference?) 命名空间中不存在类型或命名空间名称(是否缺少程序集引用?)- 无法引用 class - The type or namespace name does not exist in the namespace (are you missing an assembly reference?) - Can't reference a class 找不到类型或名称空间名称“ My_Interface_Name”(您是否缺少using指令或程序集引用?) - The type or namespace name 'My_Interface_Name' could not be found (are you missing a using directive or an assembly reference?) WPF/MVVM:“无法加载文件或程序集”和“类型引用找不到类型” - WPF/MVVM:'Could not load file or assembly' and 'Type reference cannot find type'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM