Visual Studio saying name doesn't exist in current context

c#, visual-studio-2010

Solution

This can occur when namespaces, classes and variables become tangled when they have the same name. I have suffered with this before. Intellisense told me I was right, the compiler told me I was wrong! I trusted the compiler!

You have 2 options that I can think of

Search your code for Foo, and see it it is being used for something other than the static class.

Fully qualify the Foo.bar() call. `MyApplication.This.That.Foo.bar();`

Do it in that order...it's better to elegantly resolve the issue so you can just call Foo.bar() as this is more readable and maintainable than having `MyApplication.This.That.Foo.bar();` all over the place!

Problem

I am calling a static method on a class like ``` Foo.bar() ``` Visual studio's intellisense recognizes Foo and autocompletes bar for me (it highlights Foo and everything like it is working fine). Everything looks fine until I go to build the project, and it throws an error saying the name Foo doesn't exist in current context. I am using this static method call in other files, so I know the class is ok. The situation is too big to post code, so I am mostly looking for reasons to start looking into that would cause intellisense to function normally but get errors on compile like this.

Original source

Related problems