我已经研究了一段时间,现在试图找到发生以下情况的原因,但 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
另外,需要说明的是,我没有收到关于此项目中其他文件的任何其他错误,因此这似乎不是其他文件未编译的结果。
更新:可以在此处下载为我生成错误的示例项目: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/