Studies show that good grammar leads to more promotions and higher salaries. Write with Grammarly

C# Error CS0138 – A using namespace directive can only be applied to namespaces

Compiler Error

CS0138 – A using namespace directive can only be applied to namespaces; ‘type’ is a type not a namespace

Reason for the Error

You will receive this error in C# when you use a class instead of the namespace as parameter when using keyword is used.

In the below code, we are trying to import System.Console with the using keyword which results in the CS0138 error.

using System.Console;
namespace DeveloperPublishNamespace
{
    public class DeveloperPublish
    {
        public static void Main()
        {
        }
    }

}

Error CS0138 A ‘using namespace’ directive can only be applied to namespaces; ‘Console’ is a type not a namespace. Consider a ‘using static’ directive instead ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 1 Active

Solution

To fix the error code CS0138, ensure that you use the namespace as parameter when the using directive is used in C#.