Getting "Type or Namespace Name Could Not Be Found" But Everything Seems Ok

Getting type or namespace name could not be found but everything seems ok?

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

It can happen in two ways:

  1. a client profile project referencing a full framework project; or
  2. an older framework version targeting a newer framework version

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:

  • Project A targets the Client Profile framework
  • Project A references Project B
  • Project B targets the full framework

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).

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:

  • 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)

  • 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)

The type or namespace name could not be found

See this question.

Turns out this was a client profiling issue.

PrjForm was set to ".Net Framework 4 Client Profile"
I changed it to ".Net Framework 4", and now I have a successful build.

Thanks everyone!
I guess it figures that after all that time spent searching online, I find the solution minutes after posting, I guess the trick is knowing the right question to ask..

VS2019: The type or namespace name could not be found

It was visual studio intellisense problem and following this steps helps me resolve it

  1. Clean solution
  2. Close visual studio
  3. Delete .suo file located relatively to source in: .vs\SolutionName\v16\.suo
  4. Reopen VS and build solution

Getting type or namespace name could not be found but everything seems ok?

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

It can happen in two ways:

  1. a client profile project referencing a full framework project; or
  2. an older framework version targeting a newer framework version

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:

  • Project A targets the Client Profile framework
  • Project A references Project B
  • Project B targets the full framework

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).

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:

  • 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)

  • 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)

How to fix DisplayInventory.cs(17,54): error CS0246: The type or namespace name 'GridLayoutGroup' could not be found?

How to solve this

You have missing a reference to the namespace which contains the class GridLayoutGroup. If you hover your mouse over the red line under GridLayoutGroup (provided you use visual studio as your IDE) then a light bulb should appear. Hover your mouse over the light bulb, you will have an option like "Using UnityEngine.UI" click on it and your problem will be solved.

You can do this manually as well, just go to the start of your file, make an empty line and type: Using UnityEngine.UI

Why is this happening?

The compiler divides classes into logical units called namespaces. This helps keeping your project organized, making it easier to code. If you want to acces a namespace from outside, you have to either specify the namespace from which you want your class (UnityEngine.UI.GridLayoutGroup) or add the using statement to the file, so whenever you type a class name, the compiler will look for that class in all the included namespaces as well.

The type or namespace name 'System' could not be found

I attempted to re-create your issue and came up with a similar error when the solution was created in visual studio 2013 and then tried building it in in vs 2015.

I was able to get a successful build once I reinstalled NuGet Package Manager (and closed, then reopened VS 2015).

References / Credit

There are several SO questions relating to build issues via with earlier version of NPM for VS 2015 (i.e. I'm just passing along what I've tried and worked out). Recurring resolution is usually update / reinstall NPM or change execution policy in power shell. I tend to like the update + restart approach to avoid tinkering with the black boxes in windows. one source: https://stackoverflow.com/a/32251092/1158842 There may also be an issue of MSBuild Integrated solutions, in which case migrating away from the NuGet resources in the solution could do the trick.

Source: https://stackoverflow.com/a/31811461/1158842

Compilation Error: The type or namespace name could not be found

I made the mistake of not formatting the directory on my server using IIS. If anyone comes across this make sure you do that!!!



Related Topics



Leave a reply



Submit