wpf 未定义的 CLR 命名空间

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

Undefined CLR namespace

wpf

提问by Garth Marenghi

I have the following:

我有以下几点:

Error! Error!

错误! 错误!

The error says The 'clr-namespace' URI refers to a namespace '{0}' that is not included in the assembly.

错误显示“clr-namespace”URI 引用了未包含在程序集中的命名空间“{0}”。

I've build and rebuild but nothing happens. I'm sure this must work, because a WPF demo app that I downloaded has everything the same. What's going on?

我已经建立和重建,但没有任何反应。我确信这一定能奏效,因为我下载的 WPF 演示应用程序的所有内容都相同。这是怎么回事?

回答by Willem van Rumpt

Assuming your ViewModel folder isn't empty (or there actually is a type with BlooblieBlablie.ViewModelas its namespace), and BlooblieBlablieis the assembly name, the following should work:

假设您的 ViewModel 文件夹不是空的(或者实际上有一个类型BlooblieBlablie.ViewModel作为其命名空间),并且BlooblieBlablie是程序集名称,以下应该工作:

xmlns:vm="clr-namespace:BlooblieBlablie.ViewModel;assembly=BlooblieBlablie"

回答by Maciej Rogoziński

I had similar problem when project's solution platform was set to x64. When I changed it to x86 problem went away.

当项目的解决方案平台设置为 x64 时,我遇到了类似的问题。当我将其更改为 x86 时,问题就消失了。

Here is some explanation: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/6379d330-f382-4b4d-a690-e89326ab4c72

这里有一些解释:http: //social.msdn.microsoft.com/Forums/en-US/wpf/thread/6379d330-f382-4b4d-a690-e89326ab4c72

回答by Daniel

I had the same problem and solved it by not having my project in a path with hash-mark.

我遇到了同样的问题,并通过不在带有哈希标记的路径中放置我的项目来解决它。

E.g D:#Temp had to be D:\Temp

例如 D:#Temp 必须是 D:\Temp

I guess there's someone at Microsoft having missed an EscapedCodeBase in conjunction with the URI.

我猜微软有人错过了与 URI 结合使用的 EscapedCodeBase。

回答by Eric C

I got this after Windows 7 computer crash when I was in solution in Visual Studio 2008. It seems to have blanked out the start-up configuration. I reset this and then it could find the name-space. This is one cause - probably not the major one - but just in case you have same.

当我在 Visual Studio 2008 中使用解决方案时,我在 Windows 7 计算机崩溃后得到了这个。它似乎已经清空了启动配置。我重置它,然后它可以找到命名空间。这是一个原因 - 可能不是主要的 - 但以防万一你有同样的情况。

回答by Cloud9999Strife

I had the same error message given to me. But the underlying problem was different. I moved my MainWindow.xaml to a different folder, and I forgot to update my App.xaml StartupUri. I then updated my StartupUri in my App.xaml and the problem was fixed.

我收到了同样的错误信息。但根本的问题是不同的。我将 MainWindow.xaml 移到了另一个文件夹,但忘记更新我的 App.xaml StartupUri。然后我在 App.xaml 中更新了我的 StartupUri,问题得到解决。

回答by Daniel Hilgarth

Well, as far as I can see, that namespace simply doesn't exist ;-) In your ViewModel folder is no file. And without file, there is no namespace. Namespaces are not defined by folder structure but inside source files.

好吧,据我所知,该命名空间根本不存在 ;-) 在您的 ViewModel 文件夹中没有文件。没有文件,就没有命名空间。命名空间不是由文件夹结构定义的,而是在源文件中定义的。

回答by Heinzi

Judging from your screenshot, your ViewModelfolder seems to be empty. If there are no classes in the namespace BlooblieBlablie.ViewModel, the namespace does not exist yet.

从你的截图来看,你的ViewModel文件夹似乎是空的。如果命名空间中没有类,则命名BlooblieBlablie.ViewModel空间尚不存在。

回答by Falk Seifert

Also verify the "BuildAction" of the .xaml files (see file properties). Should be "Page". After I moved files and renamed the namespace this setting changed somehow to "CodeAnalysisDictionary". This also leeds to this error.

还要验证 .xaml 文件的“BuildAction”(请参阅​​文件属性)。应该是“页面”。在我移动文件并重命名命名空间后,此设置以某种方式更改为“CodeAnalysisDictionary”。这也会导致此错误。

回答by user711227

I had the same problem today after I had to rename class (and file with it) in the namespace. So I was able to solve it by deleting .slnfile, then run .csprojand recreate .slnfile.

在我不得不重命名命名空间中的类(和带有它的文件)后,我今天遇到了同样的问题。所以我能够通过删除.sln文件来解决它,然后运行.csproj并重新创建.sln文件。

回答by Dave

I've had the same issue, mine was self inflicted due to copying and pasting code from another source into my project and renaming objects as I went without building first.

我遇到了同样的问题,由于将代码从另一个来源复制并粘贴到我的项目中,并在没有先构建的情况下重命名对象,这是我自己造成的。

So, this means Visual Studio or the compiler do not pick up on incorrect references (eg, in my code I had this:

因此,这意味着 Visual Studio 或编译器不会接收到不正确的引用(例如,在我的代码中,我有这个:

MyObect mo = new MyObect();

When I copied the code over, I corrected the spelling of MyObectto MyObjectbut, Visual Studio has still referencing MyObect and didn't give any warnings about this. And this was code was part of a .XAML file and as such, I was not only getting the error message you were, but also .g.cs errors too. All of them pointing to the incorrectreasons.

当我复制代码时,我更正了MyObectto MyObjectbut的拼写 ,Visual Studio 仍然引用了 MyObect 并且没有对此给出任何警告。这是代码是 .XAML 文件的一部分,因此,我不仅收到了错误消息,还收到了 .g.cs 错误。他们都指出了不正确的原因。

This was also occuring in the ResourceDictionary (within my datatemplate declarations for all my VM binding)

这也发生在 ResourceDictionary 中(在我所有 VM 绑定的数据模板声明中)