ardmore

I have two class

Code Block

class TestUrl

{

public static void Main()

{

string strOut;

CSDownloadURL web = new CSDownloadURL();

web.setURL1("http://www.google.com");

web.DownloadURL(out strOut);

Console.WriteLine(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();

}

}

why

Thanks



Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

eradicator

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

[STAThread]
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.






Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

IsshouFuuraibou

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.





Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

Sam Pearson

Make sure the Build Action of the file containing TestUrl is set to 'Compile'.





Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

ardmore

Thanks everybody's warm help.

Now I am going to improve my code.

Suppose the icon maps on http://www.google.com/ 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





Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

vinoth kumar.R

please delete or comment the program.cs file lines then the error will cleared. this is because already program.cs contains main() function.






Re: Visual C# General ConsoleApplication2.exe' does not contain a static 'Main' method suitable for an entry point

JamesSlab

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];

[STAThread]
static void main(string[] args)
{
//start to initialise and cleanup file
ThreadStart clean_up = new ThreadStart(Init_fileclean.run);
Thread f_clean = new Thread(clean_up);
f_clean.Start();


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

......