Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is only a parameter-less Main method considered as a "valid startup object" for a C# project?

I downloaded a zip of source files containing a C# project with multiple entry points / Main methods. Since I wanted to tinker around, I created another one like this in a new type/class

class MyExperiments
   {
      static void Main(String[] args)
      {
         // do something
      }
   }

then I switched to project properties. Simply switch the startup object to MyExperiments eh? To my surprise, the dropdown didn't have it. I rebuilt, made the method public, tried a whole lot of stuff.. but to no avail. Finally I edited the .csproj manually in notepad and then it worked. More tinkering around, I removed the parameters to make it

static void Main()

and now VS Project properties could 'see' the startup object. So now I could select it using the dropdown. I then added the String[] back and everything still worked.

Seems a bit weird to me (because the most common form is a Main method with parameters for command line args from the C/C++ times). MSDN says the dropdown will contain valid startup objects if they exist in your project.

like image 900
Gishu Avatar asked Dec 23 '22 10:12

Gishu


1 Answers

Good thing you copy-pasted it, it is the capital 'S' in Main(String[] args). Apparently VS uses some text matching, and it's case sensitive. As it probably should be.

like image 175
Henk Holterman Avatar answered Dec 31 '22 20:12

Henk Holterman