wpf XML 命名空间“yyy”中不存在标签“xxx”/找不到引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6483581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The tag "xxx" does not exist in XML namespace"yyy" / Reference could not be found
提问by Maya
I have a winform usercontrol than I want to add to wpf project.
我有一个 winform 用户控件,而不是我想添加到 wpf 项目中。
I added the relevant references (WindowsFormsIntegration, SystemWindowsForms and my user control dll) and added this row in my XAML:
我添加了相关引用(WindowsFormsIntegration、SystemWindowsForms 和我的用户控件 dll)并在我的 XAML 中添加了这一行:
xmlns:MyControl="clr-namespace:xx.xx.xx;assembly=xx.xx"
And then this:
然后这个:
<WindowsFormsHost><MyControl:control></MyControl:control></WindowsFormsHost>
When I write "MyControl:" the "control" is automated show up that mean VS recognize the control and all references added ok... but when I compile the project this give me the error in the title.
当我编写“MyControl:”时,“控件”会自动显示,这意味着 VS 识别控件并且添加的所有引用都正常......但是当我编译项目时,这给了我标题中的错误。
Edit
编辑
Its very strange when I'm compile the all project i've got error "The type or namespace name "xx' could not be found..." but I added all the refernces and the VS recognize the namespace so why the compiler don't found them? If this problem will be solved I beleive the other problem also will disappear.
当我编译所有项目时,这很奇怪,我遇到错误“找不到类型或命名空间名称“xx”...”但我添加了所有引用并且 VS 识别了命名空间,所以编译器为什么不这样做没找到?如果这个问题解决了,我相信其他问题也会消失。
回答by Mohammed A. Fadil
The solution is: Go to your project properties and change the Target Framework
from Client Profile
to the full version of the .Net you are using, see the image below. This problem happens if your DLL targets the full .NET Framework, and your WPF Application (main project) targets .Net Client Profile.
解决方案是:转到您的项目属性并将您正在使用的 .Net的Target Framework
from更改为Client Profile
完整版本,请参见下图。如果您的 DLL 以完整的 .NET Framework 为目标,而您的 WPF 应用程序(主项目)以 .Net Client Profile 为目标,则会发生此问题。
回答by Foole
This happened to me when I included the assembly name in the namespace definition, but both controls were in the same assembly. Just removing the assembly part of the namespace declaration solved it.
当我在命名空间定义中包含程序集名称时,这发生在我身上,但两个控件都在同一个程序集中。只需删除命名空间声明的程序集部分即可解决。
回答by Akash Kava
Visual Studio will load the reference only for reflection so it will show correct intellisense correctly. But in order to compile, compiler will need all the dlls that your referenced dll is dependent on. So visual studio will show intellisense for mycontrol as it can find it in reference. But your myontrol may reference other dlls which you may not have added. You will have to add dependent references of mycontrol in your project too.
Visual Studio 将仅为反射加载引用,因此它将正确显示正确的智能感知。但是为了编译,编译器将需要您引用的 dll 所依赖的所有 dll。因此,visual studio 将显示 mycontrol 的智能感知,因为它可以在参考中找到它。但是您的 myontrol 可能会引用您可能未添加的其他 dll。您还必须在项目中添加 mycontrol 的依赖引用。
回答by thailandmatt
It could also be that the target framework is different between your projects. We host a class library dll with the WPF pages, and it was targeted to 'Any CPU', but the host application was targeted to 'x86'. Once they matched, the problem went away.
也可能是您的项目之间的目标框架不同。我们使用 WPF 页面托管一个类库 dll,它的目标是“任何 CPU”,但宿主应用程序的目标是“x86”。一旦它们匹配,问题就消失了。
回答by Larry
I ran into the same "The type or namespace name 'xx' could not be found..."issue.
我遇到了同样的“找不到类型或命名空间名称‘xx’...”的问题。
It disappears when I moved my Visual Studio files on a local drive. They were stored on a shared network directory before. I dont know the root cause of this, but at least I can have my designer running now.
当我在本地驱动器上移动我的 Visual Studio 文件时它消失了。它们之前存储在共享网络目录中。我不知道这的根本原因,但至少我现在可以让我的设计师运行。
回答by Tom Savage
I've encountered this problem before and replacing <MyControl:control></MyControl:control>
with just <MyControl:control/>
fixed it for me.
我以前遇到过这个问题,并替换<MyControl:control></MyControl:control>
为刚刚<MyControl:control/>
为我修复的。
No idea why though. It seems like the first form is only for controls which can contain other controls.
不知道为什么。似乎第一种形式仅适用于可以包含其他控件的控件。