Resolved How Does Visual Studio For macOS See a Namespace That Does Not Exist?

carla_rogers

Member
Joined
Jun 17, 2022
Messages
5
Programming Experience
10+
SANITY CHECK
Please accept my apology for a long post. Even though this post is long, to provide context, the question I have is an easy, I think.

BACKGROUND
For the last 10 years, I worked with native linux servers, php, apache and other non-microsoft technology. Getting back into the MS world now. Running Visual Studio for Mac, working with C#. Working an exercise to make sure I have a handle on how the different parts of a C# App connect to one another.

SITUATION CREATING A PROBLEM IN MY BRAIN
The problem I am needing some help to be sane with is I have one project that is missing a namespace, because I deleted it as part of a test. That much is ok.

THE PROBLEM
Visual Studio is acting like the namespace is there and also as if it is not there.

PROJECT ATTACHED TO TWO DIFFERENT SOLUTIONS IN DIFFERENT INSTANCES OF VISUAL STUDIO
In one of the solutions, the project is broken as expected.

In the other solution, the project acts as if thee is a namespace that is not there. There never was anything in the namespace, but it has to exist for the project to run.

REMINDS ME OF A BROWSER NOT CLEARING CACHE WHEN TESTING CHANGES TO A WEB PAGE
It seems similar to the problem that happens in web app testing when the browser holds onto cache and makes it look like changes just made to the website are not having an effect.

ERROR MESSAGE COMING AS EXPECTED IN ONE SOLUTION, NOT THE OTHER
The type or namespace name 'TestNew' could not be found (are you missing a using directive or an assembly reference?)

BOTTOM LINE
Can you fill me in on how this happens? Is there some cache somewhere I can delete to fix this problem?

Thank you.



1.png
 
Solution
For the last 10 years, I worked with native linux servers,
In the Linux world, whenever you pick up any source only updates, often you need to run make clean followed by make. That is a clean build.

So the equivalent in Visual Studio is to pick "clean inputEditing", followed by "build inputEditing". I've never put much reliance on "rebuild" from (Windows) Visual Studio just because I've been burned too many times by the older 2005 and 2008 versions. Supposedly it had gotten better by the 2012 version, but old habits die hard.
I deleted it as part of a test.
How exactly did you delete it?

Did you delete the project underneath from Visual Studio? Did you delete it by going in Visual Studio's Solution Explorer?

Also after to deleted it, did you do a clean build or just try to compile?
 
How exactly did you delete it?

Did you delete the project underneath from Visual Studio? Did you delete it by going in Visual Studio's Solution Explorer?

Also after to deleted it, did you do a clean build or just try to compile?
Thank you for taking time to respond to my question.

The project named NewTest had a file. The started like this:

C#:
namespace NewTest
   
    public class NewTest
    {
       
        public NewTest()
        {
           
           
        }
       
       
    }

I deleted the file by right-clicking, selecting DELETE and then yes in he confirm box
 
And then did you do a clean build after deleting?

Also you'll need to be be more precise about your use of words. There is a difference between a namespace, a project, and a file. In your first post you seemed to be using namespace and project interchangeably, and then now you've added another dimension: file.
 
And then did you do a clean build after deleting?

Also you'll need to be be more precise about your use of words. There is a difference between a namespace, a project, and a file. In your first post you seemed to be using namespace and project interchangeably, and then now you've added another dimension: file.
I suspect this thing you call "Clean build" could be central to resolving this issue.

A clean build eh?

To be honest, I am not absolutely certain I ran any kind of build, and if I did, I would not know a clean build from a dirty demolition.

Here is my final answer: of course I did a build after the deleting the file that seemed to contain that undefinable something we call NAMESPACE. And of course it was clean from where I could see of what it was doingSeems like FILE works about the same.

In creating the build aspect of c# and dotnet, MIcrosoft deserve a lot of credit for preserving a solid lookalike of the modern computer's golden era (1950s-1960s).

Before encapsulating into "clean" or "other than clean" everything I am looking at with regard to a clean build, respect for all reasonable diligence compellled me to make the sketch show below

1655617590690.png
 
For the last 10 years, I worked with native linux servers,
In the Linux world, whenever you pick up any source only updates, often you need to run make clean followed by make. That is a clean build.

So the equivalent in Visual Studio is to pick "clean inputEditing", followed by "build inputEditing". I've never put much reliance on "rebuild" from (Windows) Visual Studio just because I've been burned too many times by the older 2005 and 2008 versions. Supposedly it had gotten better by the 2012 version, but old habits die hard.
 
Last edited:
Solution
In the Linux world, whenever you pick up any source only updates, often you need to run make clean followed by make. That is a clean build.
Thank you.

So the equivalent in Visual Studio is to pick "clean inputEditing", followed by "build inputEditing". I've never put much reliance on "rebuild" from (Windows) Visual Studio just because I've been burned too many times by the older 2005 and 2008 versions. Supposedly it had gotten better by the 2012 version, but old habits die hard.
This is very helpful, thank you.

Also you'll need to be be more precise about your use of words. There is a difference between a namespace, a project, and a file. In your first post you seemed to be using namespace and project interchangeably, and then now you've added another dimension: file.
I forgot to respond to this earlier. Your comment here aims at my primary objective, understanding how the various constructs go together to make a whole system. With regard to the term NewTest as it connected with files and namespace:

.. The project name, NewTest, was assigned by default, based on the command line default directory at the time when the command to make the project was issued. In other words, in a directory named NewTest, at the command line enter

dotnet new console

creates a new project in that folder, NewTest.

Then, following steps in a tutorial, I right-clicked on the project in VS, and added a new file, with the same name as the project and directory, NewTest.cs . That file by default has he following line:

namespace NewTest;

I hypothesized that the namespace was created by the declaration at the start of the file called NewTest. I deleted the file and rebuilt the project as part of a test to isolate the place where the namespace gets its name... the directory? The file (other files were declaring other namespaces in the same project)? The declaration of namespace in a file? Does the filename have to have the same name as the namespace? Does the project have to have the same name as the directory? Do either of those two have anything to do with namespace? Recently, I have seen systems that require that classes are defined in files that have the same name as the class, which struck me as a terrible requirement, and I am looking for that sort of thing in C#/dotnet. I have never had any idea where the boundaries of namespaces are.

Epilog: I used to be even more critical toward structures like these, being certain there must be a better way to setting up the linkages between the pieces that make a system. A few years ago, I had a chance to setup this kind of thing in my own framework. I was surprised when I concluded the best I could do in my framework is require that a "page set" ---- files that are part of a web page and not shared by other pages in my framework -- must be in a directory by the same name, and the support files for that page must be in a subdirectory that also has the same name.

If I could figure out how to put an image in this post, I would provide an illustration of what I am talking about. Instead, if you have read this much, I hope you will take a few seconds to view the image at this link, which shows how I coupled a page, directory, a file in that directory, and a subdirectory all through giving them the same name
Crazy Connections
https://legacy-systems.biz/longview2500/public_links/public/programming/crazy_connections

It would take me awhile to reconstruct the rationale that led me to conclude that the best solution for putting pages onto a site in the framework of my dreams was to require precisely the same name on two directories and a php page.

So now, I am looking to understand how things go together in the framework of Microsoft's dream.
 
Last edited:
So the equivalent in Visual Studio is to pick "clean inputEditing", followed by "build inputEditing".
This step caused the project build to fail, as it should have, after the file with the namespace statement was deleted.

==============================

There is something I want to acknowledge. The time and attention you gave to this thread is above and beyond what anyone in my position can expect in a forum like this. You did a lot to help me. Thank you.

I will pay attention to new questions coming into this forum, and to pass on some help when I can.
 

Latest posts

Back
Top Bottom