Skip to main content

How to Resolve Warning "CS0028: 'function declaration' has the wrong signature to be an entry point" in C#

The Compiler Warning CS0028 indicates that you have defined a method named Main, but it does not adhere to the strict requirements of a C# application Entry Point.

The C# compiler assumes that if you name a method Main, you intend it to be the startup method for your program. If that method is missing the static keyword, has incorrect parameters, or an invalid return type, the compiler issues this warning to tell you: "I see a method named Main, but I can't use it to start the application because the signature is wrong."

This guide explains the valid signatures for an entry point and how to correct this warning.

Understanding Valid Entry Points

For the Common Language Runtime (CLR) to launch your application, the Main method must follow a specific contract. It must be static (so it can run without an object instance) and it must return either void, int, or a Task (for async apps).

Valid Signatures List:

  • static void Main()
  • static void Main(string[] args)
  • static int Main()
  • static int Main(string[] args)
  • static Task Main()
  • static Task<int> Main()
  • static Task Main(string[] args)
  • static Task<int> Main(string[] args)

Any Main method that deviates from this list triggers CS0028.

note

If your program has no valid Main method at all, you will see Error CS5001 ("Program does not contain a static 'Main' method suitable for an entry point"). CS0028 is usually the precursor to CS5001.

Scenario 1: Missing the 'static' Keyword

This is the most common cause. Developers often make Main public but forget to make it static. Because the application hasn't started yet, there is no instance of your Program class, so the CLR cannot call a non-static method.

Example of Mistake

class Program
{
// ⛔️ Warning CS0028: 'Program.Main(string[])' has the wrong signature
// to be an entry point.
// Cause: It is missing 'static'.
public void Main(string[] args)
{
System.Console.WriteLine("Hello World");
}
}

Solution

Add the static modifier.

class Program
{
// ✅ Correct: Static allows the CLR to call this without creating 'new Program()'
public static void Main(string[] args)
{
System.Console.WriteLine("Hello World");
}
}

Scenario 2: Incorrect Parameter Types

The entry point accepts arguments from the command line. The standard imposes that these arguments must be passed as an Array of Strings (string[]). You cannot use a List<string>, a single string, or other types like int as the entry parameter.

Example of Mistake

class Program
{
// ⛔️ Warning CS0028: Wrong signature.
// Cause: The parameter must be string[], not string or int.
static void Main(string args)
{
// ...
}
}

Solution

Use string[] args if you need parameters, or leave the parentheses empty () if you don't.

class Program
{
// ✅ Correct: Accepts command line arguments as an array
static void Main(string[] args)
{
foreach(var arg in args)
{
System.Console.WriteLine(arg);
}
}

// ✅ Correct: Accepts no arguments
// static void Main() { }
}

Scenario 3: Incorrect Return Types

A standard Main method can return:

  1. void (Nothing).
  2. int (An exit code to the Operating System, where 0 usually means success).
  3. Task / Task<int> (For async/await support).

Returning any other type, such as string, bool, or a custom object, is invalid for an entry point.

Example of Mistake

class Program
{
// ⛔️ Warning CS0028: Wrong signature.
// Cause: The OS does not know how to handle a 'bool' return value.
static bool Main()
{
return true;
}
}

Solution

Change the return type to int (if you want to return a status code) or void.

class Program
{
// ✅ Correct: Returns an integer exit code (0 = Success)
static int Main()
{
return 0;
}
}

Conclusion

CS0028 is a warning that says: "You named a function Main, so I assume you want to run it, but you defined it incorrectly."

To fix it, ensure your Main method matches the checklist:

  1. Is it static?
  2. Does it return void, int, or Task?
  3. Does it take either no parameters or a string[]?