Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to I find out what namespace a missing identifier belongs to?

Tags:

c#

When I compile my c# project in visual studio, I get the error ...

Error   1   The name 'FilterConfig' does not exist in the current context ...

I guess I need to add a 'using' statement or add a package or something. In general, whats the best ways to try and figure out what package/namespace missing things might belong to? E.g is there a way to search all common packages to find a member?

I've searched on msdn but cant seem to find it.....

http://social.msdn.microsoft.com/Search/en-US?query=filterconfig&emptyWatermark=true&searchButtonTooltip=Search%20MSDN&ac=4#refinementChanges=33,26,59&pageNumber=1&showMore=false

Update: This particular example is for MVC4, however I am interested for a general solution (or multiple solutions) as I work on console apps also.

I've often come across this problem when using incomplete tutorials I've found on the web. So the references may not be present at all. Usually they turn out to be for Microsoft.

like image 613
spiderplant0 Avatar asked Jan 16 '26 18:01

spiderplant0


2 Answers

General Troubleshooting Steps

Right-click on the identifier. In the context menu, you should see Resolve… ▹. In the sub menu you should see two lists which contain all of the namespaces in all the project's loaded references which contain a symbol with that name.
enter image description here

Selecting an item from the first list will add a using directive to the current file. Selecting an item from the second list will modify that use of the identifier to be globally qualified. Just select the option you want to use.

If the identifier cannot be found in any of the loaded references (either you are missing a reference, or it's a typo), then you won't see this list. In that case, you should make sure all the references are loaded correctly (there will typically be an exclamation mark next to it could not be loaded) and check the spelling of the identifier.

If all the references are correctly loaded, and your sure the identifier is spelled correctly, it's likely the symbol was renamed, or removed entirely from the project. Using the Rename… tool (also found by right-clicking on an identifier) can help to avoid this in the future. It's also possible the code snippet in question was taken out of a project where that symbol was defined and you need to include more code from that project to make the code functional. Finally, it may simply be that you're just missing a necessary reference. If this is the case you should investigate where this code came from and what libraries it uses, either by asking the original developer, or if it came from an online source, review the source to see if any more details are provided.

Regarding This Specific Issue

That's about it for general troubleshooting. However, for your specific issue, these steps may only get you so far, and you need to know more about where this exact class comes from in order to resolve it. Microsoft's MVC4 project template includes a number files in the App_Start folder. You typically start out with something like this (NOTE: not every MVC4 project template will contain the same files):
MVC4 project template

And these will typically be referenced in your Global.asax file like this:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();

        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        AuthConfig.RegisterAuth();
    }
}

If this is where you're seeing the issue, it's likely that somehow the project was broken in some way. Either the FilterConfig class was renamed or removed entirely (as I stated above). It's also possible that the project started out life as an MVC3 template (which I believe didn't include the FilterConfig class) or perhaps a pre-release version of MVC4, and in migrating to full MVC4 template, this was left out. In any case, I would recommend you create a brand new MVC4 project and see what's different between the your project and the new one.

Now, if for any reason the new project doesn't compile and run like it should, then the template itself is probably damaged somehow. In this case, I'd recommend you uninstall MVC4 and re-install it from the official source.

like image 155
p.s.w.g Avatar answered Jan 19 '26 18:01

p.s.w.g


Additionally to what p.s.w.g said (which you should normally do): I guess that you're using ASP.NET MVC or ASP.NET Web API and that the FilterConfig class is located in the *App_Start* folder. If so, you should remove the *App_Start* from the end of the namespace. After doing so you can call it without a problem in the Global.asax file.

Like said, normally you should use the solution provided by p.s.w.g, but for startup tasks this is the way Microsoft does it in its templates.

like image 41
Horizon_Net Avatar answered Jan 19 '26 19:01

Horizon_Net