0
votes

Edit: Changing the class name or namespace name so that the namespace and class don't have the same name doesn't fix this issue.

I have this super simple code:

Program.cs:

using System;
using CodeCleaner;

class Program
{

    private static void Main(string[] args)
    {
        Console.WriteLine("DocTypeChecker instantiated");

        var codeCleaner = new CodeCleaner.CodeCleaner();
    }
}

CodeCleaner.cs:

using System;

namespace CodeCleaner
{
    public class CodeCleaner
    {

        public CodeCleaner()
        {
            Console.WriteLine("CodeCleaner instantiated");
        }

    }
}

This produces the following error when I try to compile when I run $ csc Program.cs:

Program.cs(4,7): error CS0246: The type or namespace name 'CodeCleaner' could not be found (are you missing a using directive or an assembly reference?).

I'm definitely not missing a using directive for CodeCleaner, but what it means with assembly reference I have no idea. Other solutions on the web didn't help me in this case. Anyone know the issue here?

1
I think the issue is the same name for namespace and class name. - vik_78
That is not the issue. I tried changing the namespace name to NCodeCleaner and the issue persists (it then says namespace name 'NCodeCleaner' not found), so same issue. - erol_smsr
Is CodeCleaner in the same assembly as Program? If not, then Program's assembly needs to reference the assembly which has CodeCleaner. - Loring
If namespace and class names are the same can cause trouble but not in this case that he uses fully with name space and class name together like : new CodeCleaner.CodeCleaner() - Ashkan Mobayen Khiabani
just use the same namespace for your Program class - german1311

1 Answers

1
votes

Running csc Program.cs won't compile CodeCleaner.cs, so your assembly will be missing the CodeCleaner class and namespace. Using csc Program.cs CodeCleaner.cs should do the trick.