获取“找不到类型或命名空间名称"但似乎一切正常? [英] Getting "type or namespace name could not be found" but everything seems ok?

查看:31
本文介绍了获取“找不到类型或命名空间名称"但似乎一切正常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到了:

找不到类型或命名空间名称

type or namespace name could not be found

VS2010 中 C# WPF 应用程序的错误.这部分代码编译得很好,但突然间我收到了这个错误.我已经尝试删除项目参考和 using 语句,关闭 VS2010 并重新启动,但我仍然有这个问题.

error for a C# WPF app in VS2010. This area of code was compiling fine, but suddenly I'm getting this error. I've tried removing the Project Reference and the using statement, shutting VS2010 and restarting, but still I have this issue.

为什么会发生这种情况的任何想法,似​​乎我在做正确的事情重新参考 &使用语句?

Any ideas why this might be occurring, where it seems like I'm doing the right thing re Reference & using statement?

我还在 VS2010 中注意到那个命名空间的智能感知工作正常,所以看起来 VS2010 有项目引用并且一方面看到命名空间,但在编译期间没有看到它?

I also noted in VS2010 that intellisense for that namespace is working ok, so it seems like VS2010 has the project reference and is seeing the namespace on one hand, but during compile doesn't see it?

推荐答案

这可能是两个项目之间 .Net 框架版本不兼容的结果.

This can be the result of a .Net framework version incompatibility between two projects.

它可以通过两种方式发生:

It can happen in two ways:

  1. 引用完整框架项目的客户资料项目;或
  2. 针对较新框架版本的旧框架版本

例如,当应用程序设置为面向 .Net 4 Client Profile 框架,并且它引用的项目面向完整的 .Net 4 框架时,就会发生这种情况.

For example it will happen when an application is set to target the .Net 4 Client Profile framework, and the project it references targets the full .Net 4 framework.

为了更清楚地说明这一点:

So to make that clearer:

  • 项目 A 以客户资料框架为目标
  • 项目 A 引用项目 B
  • 项目 B 以完整框架为目标

这种情况下的解决方案是升级应用程序的框架目标(项目 A),或者降级引用程序集的目标(项目 B).完整框架应用可以引用/使用客户端配置文件框架程序集,但反过来不行(客户端配置文件不能引用完整的框架目标程序集).

The solution in this case is to either upgrade the framework target of the application (Project A), or downgrade the target of referenced assembly (Project B). It is okay for a full framework app to reference/consume a client profile framework assembly, but not the other way round (client profile cannot reference full framework targeted assembly).

请注意,在 VS2012 或 VS2013(使用 .Net 4.5 作为默认框架)中创建新项目时,也会出现此错误:

Note that you can also get this error when you create a new project in VS2012 or VS2013 (which uses .Net 4.5 as the default framework) and:

  • 引用项目使用 .Net 4.0(当您从 VS2010 迁移到 VS2012 或 VS2013 然后添加新项目时,这很常见)

  • the referencing project(s) use .Net 4.0 (this is common when you have migrated from VS2010 to VS2012 or VS2013 and you then add a new project)

引用的项目使用更高版本,即 4.5.1 或 4.5.3(您已将现有项目重新定位到最新版本,但 VS 仍然创建了针对 v4.5 的新项目,然后您从新项目中引用那些旧项目)

the referenced projects use a greater version i.e. 4.5.1 or 4.5.3 (you've re-targeted your existing projects to the latest version, but VS still creates new projects targeting v4.5, and you then reference those older projects from the new project)

这篇关于获取“找不到类型或命名空间名称"但似乎一切正常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆