wpf XML 命名空间 'clr-namespace:YYY' 中不存在标记 'XXX'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9151366/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 23:17:14  来源:igfitidea点击:

The tag 'XXX' does not exist in XML namespace 'clr-namespace:YYY'

wpfxaml

提问by álvaro García

I have implemented a converter to convert Int32 to String to be able to binding a property to a textBox.

我已经实现了一个转换器来将 Int32 转换为 String 以便能够将一个属性绑定到一个文本框。

I implement this converter in the namespace MyApp.Converters and it is called Int32ToStringConverter.

我在命名空间 MyApp.Converters 中实现了这个转换器,它被称为 Int32ToStringConverter。

Then, in my axml I add the reference to my converter as follow:

然后,在我的 axml 中,我添加了对转换器的引用,如下所示:

<Window x:Class="MusicaDB.Views.PrincipalView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
        **xmlns:converter="clr-namesapce:MyApp.Converters, aseembly=MyApp**">

Later, in windows.Resources I have:

后来,在 windows.Resources 我有:

<Window.Resources>
        <**converter:Int32ToStringConverter** x:Key="Int32ToStringConverter" />
</Window.Resources>

I get the error that the tag Int32ToString converter does not exist in the namespace MyApp.Converters,assembly=MyApp.

我收到错误消息,即命名空间 MyApp.Converters,assembly=MyApp 中不存在标记 Int32ToString 转换器。

I have the project in the local hard drive, in the project properties, the destination .NET is framework 4.0, not framework 4.0 client profile and I try to clear the solution and recompile but the problem persists.

我在本地硬盘驱动器中有项目,在项目属性中,目标 .NET 是框架 4.0,而不是框架 4.0 客户端配置文件,我尝试清除解决方案并重新编译,但问题仍然存在。

Mainly, this is the two solutions that I always find, but don't resolve my problem.

主要是,这是我总能找到的两种解决方案,但不能解决我的问题。

回答by Dan Balthaser

Another possible solution to this problem is that you're not using the same version of .Net in your project and your library.

此问题的另一个可能解决方案是您在项目和库中使用的 .Net 版本不同。

回答by H.B.

Three fixes to make here:

在这里进行三个修复:

  1. No spaces -> xmlns:converter="clr-namesapce:MyApp.Converters,aseembly=MyApp"
  2. No misspellings -> xmlns:converter="clr-namespace:MyApp.Converters,assembly=MyApp"
  3. Right delimiters -> xmlns:converter="clr-namespace:MyApp.Converters;assembly=MyApp"
  1. 没有空格-> xmlns:converter="clr-namesapce:MyApp.Converters,aseembly=MyApp"
  2. 没有拼写错误-> xmlns:converter="clr-namespace:MyApp.Converters,assembly=MyApp"
  3. 右分隔符 -> xmlns:converter="clr-namespace:MyApp.Converters;assembly=MyApp"

From the the documentation:

文档中

Note that the character separating the clr-namespacetoken from its value is a colon (:) whereas the character separating the assemblytoken from its value is an equals sign (=). The character to use between these two tokens is a semicolon. Also, do not include any whitespace anywhere in the declaration.

请注意,将clr-namespace标记与其值分隔的字符是冒号 (:),而将程序集标记与其值分隔的字符是等号 (=)。在这两个标记之间使用的字符是分号。此外,不要在声明中的任何地方包含任何空格。

回答by eppdog

I am exploring as to why this is happening, but if your converter is in the main assembly, removing the assembly= from your xmlns:converters tag should remove that build error.

我正在探索为什么会发生这种情况,但是如果您的转换器在主程序集中,则从 xmlns:converters 标记中删除 assembly= 应该会删除该构建错误。

回答by Abdur Rahim

All answers are right. And after trying all of them and you cannot configure why its happening, everything seems alright, Please restart the Visual studio.

所有的答案都是正确的。在尝试了所有这些之后,您无法配置其发生的原因,一切似乎都很好,请重新启动 Visual Studio。

That worked for me after wasting almost 1 hour. I found everything ok, but restarted the VS with administration.

在浪费了将近 1 个小时后,这对我有用。我发现一切正常,但通过管理重新启动了 VS。

回答by Hugo

For the record ... I've face a similar problem and if I removed the ";assembly=X" part from the XAML it worked fine

作为记录......我遇到了类似的问题,如果我从 XAML 中删除了“;assembly=X”部分,它工作正常

But don't really understand the reason.

但不是很明白其中的原因。

As suggested in this blog: http://zoomicon.wordpress.com/2012/07/02/fix-the-tag-xxx-does-not-exist-in-xml-namespace-clr-namespaceyyy/#comment-7761

正如本博客中所建议的:http: //zoomicon.wordpress.com/2012/07/02/fix-the-tag-xxx-does-not-exist-in-xml-namespace-clr-namespaceyyy/#comment-7761

回答by Adam Mihalcin

I see two possible causes. The first is that you misspelled "assembly" as "aseembly" in the first starred line. Changing the spelling might be enough. The second possibility is that you haven't added MyApp.dll to your project references, which appear like this

我看到两个可能的原因。第一个是您在第一个带星标的行中将“assembly”拼错为“aseembly”。更改拼写可能就足够了。第二种可能是你的项目引用中没有添加MyApp.dll,看起来像这样

enter image description here

在此处输入图片说明

in Visual Studio.

在 Visual Studio 中。

回答by Radu Cosoveanu

In my situation, I had the same problem with xmlns:local="clr-namespace:<mydefaultnamespace>". I solved this changing the order of the includes. I put it first and all was solved. A strange behaviour, but this was my workaround that I found in my situation.

在我的情况下,我遇到了同样的问题xmlns:local="clr-namespace:<mydefaultnamespace>"。我解决了这个改变包含顺序的问题。我把它放在第一位,一切都解决了。一种奇怪的行为,但这是我在我的情况下找到的解决方法。

回答by NidhinSPradeep

use the assemble tag only if it is in another project. other wise use just namespace tag alone. For me this fixed the issue

仅当它在另一个项目中时才使用 assemble 标记。其他明智的做法是单独使用命名空间标签。对我来说这解决了这个问题

回答by Simon_Weaver

There is one very obscure case when you get this error - if you're using Microsoft.mshtml.dlland you upgrade to Windows 10 anniversary edition, or as it turns out the Creator edition too.

当您收到此错误时,有一个非常模糊的情况 - 如果您正在使用Microsoft.mshtml.dll并升级到 Windows 10 周年纪念版,或者事实证明也是 Creator 版本。

Even if this isn't what happens to you make sure the library containing the component that cannot be found can be fully compiled. Look in the error list (not the grid but the Output console) for any clues.

即使这不是发生在您身上的情况,也要确保可以完全编译包含无法找到的组件的库。查看错误列表(不是网格,而是输出控制台)以获取任何线索。

In my case I was using Microsoft.mshtml.dllas part of an HTML editor and it was unregistered somehow (in the GAC).

就我而言,我Microsoft.mshtml.dll作为 HTML 编辑器的一部分使用,但不知何故(在 GAC 中)未注册。

The following article explains with screenshots:

以下文章用截图说明:

https://techninotes.blogspot.com/2016/08/fixing-cannot-find-wrapper-assembly-for.html#comment-form

https://techninotes.blogspot.com/2016/08/fixing-cannot-find-wrapper-assembly-for.html#comment-form

In short I had to run a Visual Studio command prompt (as admin) run these commands:

简而言之,我必须运行 Visual Studio 命令提示符(以管理员身份)运行这些命令:

cd C:\Windows\assembly\GAC\Microsoft.mshtml.0.3300.0__b03f5f7f11d50a3a
regasm Microsoft.mshtml.dll

I did say obscure :-) The important point is to read the errors that may be buried amongst all your warnings because there might be an important clue.

我确实说晦涩难懂 :-) 重点是阅读可能隐藏在所有警告中的错误,因为可能有重要线索。

This can be especially confusing if an Operating system update suddenly breaks your project.

如果操作系统更新突然中断您的项目,这可能会特别令人困惑。

回答by mungflesh

In my case, the assembly which contained the namespace was not physically there.

就我而言,包含命名空间的程序集实际上并不存在

I checked the references of the assembly that had the build error and looked at the properties of the referenced assembly in question.

我检查了存在构建错误的程序集的引用,并查看了相关引用程序集的属性。

I navigated to the path and discovered the assembly was indeed missing (which I realised was my own doing), giving rise to the misleading error.

我导航到路径并发现程序集确实丢失了(我意识到这是我自己做的),从而产生了误导性错误。