C# Error CS0439 – An extern alias declaration must precede all other elements defined in the namespace

C# Compiler Error

CS0439 – An extern alias declaration must precede all other elements defined in the namespace

Reason for the Error

You’ll get this error in your C# code when the declaration of the extern is done after the using declaration.

For example, let’s try to compile the below C# code snippet.

using System;
extern alias DeveloperClass;  
namespace DeveloperPublishNamespace
{
   class Program
    {      
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

You’ll receive the error code CS0439 when you build the above C# code because you are declaring the extern after the using System;

Error CS0439 An extern alias declaration must precede all other elements defined in the namespace DeveloperPublish C:\Users\Senthil\source\repos\ConsoleApp4\ConsoleApp4\Program.cs 2 Active

C# Error CS0439 – An extern alias declaration must precede all other elements defined in the namespace

Solution

You can fix this error in your C# program by ensuring that the extern declarations come before all other declarations in your program

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