0

I made a project using .NET Framework in C#. My program.cs file looks like the following:

    namespace x_y_z
{
    class Program
    {
        static void Main(string[] args)
        {
            string fileType = args[0];

            CopyFiles mf = new CopyFiles();
            mf.doCopyFiles();

            LoadData ld = new LoadData();
            ld.doLoadFiles(fileType);
        }
    }
}

The classes CopyFiles and LoadFiles are in separate files. However, no matter what I try they don't seem to be pickup by the Program class. I get the following error:

Error   CS0246  The type or namespace name 'LoadData' could not be found 
(are you missing a using directive or an assembly reference?)   

To make the new classes, I right-clicked in the Solution Viewer and added a new item.

The LoadFiles class looks like the following:

namespace x_y_z
{

    class LoadData
    {
        public doLoadFiles()
        {
          //do stuff
        }
    }

 }

Are there any suggestions?

EDIT: I noticed that my LoadData and CopyFiles are markes as "Miscellaneous Files". Any ideas on how to make them a part of the project?

EDIT2: Picture of the explorer:

sorry for the bad attempt at censoring out my name!

  • Did you add the `LoadData.cs` file to the same project as the `Program.cs` file? – Joe Sewell Apr 01 '20 at 18:37
  • So your `LoadData` and `CopyFiles` classes already exist in your project? Are they in a different namespace to your `Program.cs` by any chance? – simon-pearson Apr 01 '20 at 18:37
  • @JoeSewell I believe so. However, I just realized that they are marked as "Miscellaneous files". I'm not sure why this hapened –  Apr 01 '20 at 18:40
  • @simon-pearson they are in the same namespace –  Apr 01 '20 at 18:40
  • How did you add these files? Usually you would right click on the project or on a folder inside the project in the Solution Explorer and choose `Add > Class...`. – Olivier Jacot-Descombes Apr 01 '20 at 18:57
  • @OlivierJacot-Descombes yup, thats exactly the method I followed –  Apr 01 '20 at 18:58
  • Try Rebuild the solution. If it does not help, close the solution and reopen it. If it still does not help, close Visual Studio and then reopen your solution. – Olivier Jacot-Descombes Apr 01 '20 at 19:01
  • @OlivierJacot-Descombes no luck, tried rebooting –  Apr 01 '20 at 19:11

1 Answers1

1

Your picture of the solution explorer looks wrong. You seem to have a .csproj and a .sln inside your project.

It should look like this:

enter image description here

The first line is the solution. The second is the project.

When you first create a solution, a project with the same name as the solution is inserted. So the bold MySolution is in fact the project.

My guess is that in Visual Studio you have chosen Open a local folder instead of Open a project or solution:

enter image description here
(Note: this might look different an another Version of Visual Studio. The screenshots are from Visual Studio 2019)

Or from the File menu:

enter image description here

The option Open a local folder is only useful if you want to work with files not created with Visual Studio, e.g. a folder containing Python files but no *.sln or *.csproj file.

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
  • I see my mistake! You are right, I opened a local folder. Thank you for your help! –  Apr 01 '20 at 19:41