c# - 未定义的 CLR 命名空间 - 未找到解决方案

标签 c# .net wpf xaml namespaces

我已经研究了一段时间,现在试图找到发生以下情况的原因,但 StackOverflow 或 Google 上没有任何解决方案能够帮助我。

我有一个自定义 UserControl,它试图引用同一项目中的命名空间:

xmlns:my="clr-namespace:ColorPicker"

但是当我编译时出现以下错误:

Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace 'ColorPicker' that is not included in the assembly.

这导致无法构建我的项目或在 xaml 中引用其他自定义控件,从而生成以下类型的错误:

The type 'my:ColorSelector' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.

我已经尝试了这些帖子中给出的所有解决方案:

adding a custom namespace to xaml

WPF xmlns: The 'clr-namespace' URI refers to a namespace that is not included in the assembly

The 'clr-namespace' URI refers to a namespace that is not included in the assembly

Undefined CLR namespace

另外,需要说明的是,我没有收到关于此项目中其他文件的任何其他错误,因此这似乎不是其他文件未编译的结果。

更新:可以在此处下载为我生成错误的示例项目:http://www.filefactory.com/file/28fbmhj3f4qj/n/ColorPicker_zip

最佳答案

你的 first linked question有答案。答案是:您必须构建包含命名空间和引用的类/控件的程序集,然后才能在 .xaml 中引用它。我注释掉了您的 xaml 命名空间声明,然后注释掉了那些命名空间中的 xaml 元素,然后注释掉了由于不再声明这些元素而中断的 C# 代码。换句话说,我一直在评论,直到我能够成功构建。程序集构建完成后,我取消了 xaml namespace 声明的注释,然后是元素。这给出了关于需要在这些元素上使用 x:Name 而不是 Name 的错误,所以我这样做了。然后取消注释 C# 代码并构建它。

关于c# - 未定义的 CLR 命名空间 - 未找到解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11040051/

相关文章:

c# - 如何在 JetBrains Rider 的同一个项目中创建 MVC 和 Web API 项目?

.net - 自签名和证书颁发机构生成的证书有什么区别

c# - WPF 过滤器 ObservableCollection 与 ICollectionView

wpf - Grid 和 StackPanel,哪个性能更好?

wpf - 如何将平移命令绑定(bind)到 WPF 中 OxyPlot 的鼠标左键?

c# - 对异步 mvc Controller 的异步 jquery 调用

c# - 添加更多选项卡时如何缩小 tabItem 大小(例如 google chrome 选项卡)

c# - 在任务中包装 Start() 方法和 Completed 事件

c# - Kinect如何检测小人物

c# - 如何找出两个图片框何时在 C# WinForms 中发生碰撞