ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point



    I have two class

    Code Block

    class TestUrl


    public static void Main()


    string strOut;

    CSDownloadURL web = new CSDownloadURL();


    web.DownloadURL(out strOut);






    Code Block

    namespace Project5


    using System;

    using System.Text;

    using System.IO;

    using System.Net;

    /// <summary>

    /// Summary description for Class1.

    /// </summary>

    public class CSDownloadURL


    private string m_strURL;

    public void setURL1( string strURL )


    m_strURL = strURL;


    public void DownloadURL(out string strContents)


    WebRequest req = WebRequest.Create(m_strURL);

    WebResponse res = req.GetResponse();

    int iTotalBuff = 0;

    Byte[] Buffer = new Byte[128];

    Stream stream = res.GetResponseStream();

    iTotalBuff = stream.Read(Buffer, 0, 128);

    StringBuilder strRes = new StringBuilder("");

    while(iTotalBuff != 0)


    strRes.Append(Encoding.ASCII.GetString(Buffer, 0, iTotalBuff));

    iTotalBuff = stream.Read(Buffer, 0, 128);


    strContents = strRes.ToString();






    Monday, October 15, 2007 6:52 PM


All replies

  • An application could be made up of many many classes. The "main entry point" needs to be marked as such. When you create a console application with Visual Studio, by default it does this marking for you, so I am guessing you are either not using the Visual Studio IDE, or removed what it had done for you.


    Try changing your Main method like so:

    Code Block

    static void Main(string[] args)



    I don't know that you need the string[] args part, but believe you at least need the STAThread attribute applied.

    Monday, October 15, 2007 7:27 PM
  •  eradicator wrote:

    I don't know that you need the string[] args part, but believe you at least need the STAThread attribute applied.

    Both are actually optional (though for other reasons you have requirements to set [STAThread] or [MTAThread]). When you specify static void Main() you just indicate that you'll just drop any command line arguments.

    [STAThread] has a counterpart of [MTAThread], in general you'll use STAThread.
    Monday, October 15, 2007 9:47 PM
  • Make sure the Build Action of the file containing TestUrl is set to 'Compile'.

    Monday, October 15, 2007 10:17 PM
  • Thanks everybody's warm help.

    Now I am going to improve my code.

    Suppose the icon maps on links a map file which I may know or not its file name.

    I want to run my program to download this map file and to save it to a client side.

    How to modify the code?



    Saturday, October 20, 2007 4:06 PM
  • please delete or comment the program.cs file lines then the error will cleared. this is because already program.cs contains main() function.


    Tuesday, October 23, 2007 6:35 AM
  • I have the same error "does not contain a static 'Main' method suitable for an entry point". I used your advise on adding [STAThread] to the Main method, but doesn't help. This program has 10 Class, only one class has 'Main'. The main class is as follows, any help is much appreciated.


    to compile, I use command line csc.exe /t:exe /outTongue Tiedhuttle1.exe Shuttle1.cs

    class Shuttle1
       static int count_scan, count_check, wd_feed, kpad_int, pass_result, thread_monitor, thread_fail,
                     index_monitor, now_minute, prev_minute;
       static byte temp1, temp2;
       static bool run_infinite=true, dbase_match, valid_entrypermit;
       static string line, date_line;
       static char[] dispdate = new char[40];
       static byte[] check_byte = new byte[12];
       static byte[] card_byte = new byte[50];

       static void main(string[] args)
           //start to initialise and cleanup file
          ThreadStart clean_up = new ThreadStart(;
          Thread f_clean = new Thread(clean_up);

          //Read in configuration from config file
          ThreadStart config_read = new ThreadStart(;
          Thread con_read = new Thread(config_read);


    Saturday, February 02, 2008 3:29 PM

  • hi

    i too facing the same problem, but the difference i have added the empty project dataaccess into my web project
    Please help me in solving this problem.

    Wednesday, February 27, 2008 3:31 PM
  • I just encountered the same problem as you mentioned.

    It was because of some of your application, mainly it's console applicaiton, build without a main() method.

     just delete those console application  then it will work.

    Wednesday, February 16, 2011 2:23 AM
  • The thing to remember is that the Main method has to either have no parameters or a string array as parameters. Anything else will also cause this message.

    So, this is not ok:

    static void Main(string connectionString)


    and will throw that exception, but this will work:

    static void Main(string[] args)


    and so will this:

    static void Main()


    Joey Morgan

    Joseph M. Morgan, CSM

    Tuesday, June 11, 2013 2:01 PM