Incorrect error "The name XXX does not exist in the current context" appears in Visual Studio

John Mann 41 Reputation points
2021-09-14T11:34:13.46+00:00

Recently we have merged four Visual Studio solutions into a single solution.

Since this occurred some of our mark-up code now generates errors when performing a build. The errors appear in the form

CS0103 The name XXX does not exist in the current context nn_ProjectName_FileName

Note the project name appears to be some generated name consisting of a number, the actual project name and the file name (so for example 39_Commerce_PaymentEditor).

HOWEVER this only occurs if the mark-up file is currently displaying on a Visual Studio tab. If the file is closed then the build runs without error.

This is in Visual Studio 2019 and is occurring to all our developers, so it doesn't seem to be environment specific.

Does anyone know why this could be happening and if there is any way to prevent it?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,271 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
942 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 48,486 Reputation points
    2021-09-14T14:06:15.73+00:00

    There could be lots of causes for this but I'd personally start with just double clicking the error in the Output or Error List window and see where it goes.

    Beyond that it is hard to say without seeing some code. You mentioned form but it isn't clear if this is a WInforms or ASP.NET app. These often use resources or other designer-added stuff which uses the default namespace of the project at the point they were added. Therefore if you change namespaces/projects this will mess everything up.

    You also mentioned that this only occurs while the designer is open which also pushes me down the path of potentially bad intermediate files so I would also clean the existing code and then do a grep for this specific identifier.


  2. Karen Payne MVP 35,036 Reputation points
    2021-09-14T14:21:13.47+00:00

    Usually for a standard installation of Visual Studio one would use Move type to namespace although this is for code behind. Unsure what markup (to me that could mean HTML, Git or XMAL) you are referring too so perhaps a small code sample might help.