Visual Studio saying name doesn't exist in current context

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.

Answers


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

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

  2. 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!


I've seen this error caused by differing versions of the .NET framework in the different projects. The Class Library I built was 4.5 and the application was 4.0, but the only error it gave was namespace errors. Changing the framework version on the class library and rebuilding it, then the application, resolved the error.


Need Your Help

How do I get the associated form object of data from SQL data

c# sql winforms visual-studio-2010

I have a small application that has a ToolStrip. When the user clicks on any of the buttons, a form needs to be opened. I would like to have the ToolStrip dynamically loaded.

Back button support using routing in Sencha

html5 cordova sencha-touch extjs sencha-touch-2

I am newbie to Sencha. Can anyone please explain how to support back button in android using Sencha touch2 Routing. I have gone through Sencha document, they explained there with senarios like

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.