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#.

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...