473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

problems compiling first Windows application

I tried to compile a Windows Forms Application in Visual C# 2008 Express with this source code from the CSharpSchool tutorial at Programmer's Heaven:
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. namespace CSharpSchool
  5. {
  6.     class HelloWinForm
  7.     {
  8.         static void Main ()
  9.         {
  10.             Application.Run (new MyWindow ());
  11.         }
  12.     }
  13.     class MyWindow : Form
  14.     {
  15.         public MyWindow () : base ()
  16.         {
  17.             this.Text = "My First Windows Application";
  18.             this.Size = new Size (300, 300);
  19.             Label lblGreeting = new Label ();
  20.             lblGreeting.Text = "Hello WinForm";
  21.             lblGreeting.Location = new Point (100, 100);
  22.             this.Controls.Add (lblGreeting);
  23.         }
  24.     }
  25. }
but I got these errors:

Error 1 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.exe ' has more than one entry point defined: 'HelloWinForm.Test.Main()'. Compile with /main to specify the type that contains the entry point. C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.cs 8 21 HelloWinForm

Error 2 Program 'C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\obj\Release\HelloWinForm.exe ' has more than one entry point defined: 'HelloWinForm.Program.Main()'. Compile with /main to specify the type that contains the entry point. C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Program.cs 14 21 HelloWinForm

Error 3 'HelloWinForm.Form1.Dispose(bool)': no suitable method found to override C:\Documents and Settings\Bob\Local Settings\Application Data\Temporary Projects\HelloWinForm\Form1.Designer.cs 14 33 HelloWinForm

Feeding this into a search engine:

"visual c#" "Compile with /main"

yielded this link:

Compiler Error CS0017
Visual C# Reference: Errors and Warnings. Compiler Error CS0017 ... Compile with /main to specify the type that contains the entry point. ...
msdn.microsoft.com/en-us/library/t9k01y87.aspx

which said:

If you are using MS Visual Studio and do not want to delete the other Main() methods you can specify the class which you want as you Entry Point in Startup Object in the Project Properties under Application Tab (at least for VS2008 Express)

Going to:

Project | HelloWinForm Properties | Application | Startup Object

I discovered it wasn't set. Setting it to either HelloWinForm.Test or HelloWinForm.Program, the first two problems disappear, but not the third. I can't see how this code has more than one entry point, and I'm not at all clear on why the compiler requires these gyrations in Startup Object. None of these issues are mentioned by CSharpSchool, which claims the code I used will run as written. This is my first Windows app, and WOW! am I in the dark on this. What gives? Maybe I should just get a different tutorial. Any explanations of this or, failing that, any suggestions for which tutorial(s) I should use?
Feb 12 '09 #1
1 4489
vekipeki
229 Expert 100+
1st and 2nd error: you have two static Main() methods in your source, remove one of them - you can only have one entry point for your program (the method that is first called on start).

3rd error: you have a "Form1.Designer.cs" file which defines some Form-related methods (like Dispose) for your HelloWinForm class. But in "Form1.cs", you don't show that HelloWinForm if actually derived from Form. You should have something like:
Expand|Select|Wrap|Line Numbers
  1. partial class HelloWinForm : Form
when defining the name of your class in "Form1.cs".

Try to create a blank project, remove all forms, and then add the code again. Do not change anything before you get it running for the 1st time.
Feb 12 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Martin Bless | last post by:
The good news: Along with Python-2.4 comes really good news to Windows users. Yes, you now CAN build extension modules yourself using the SAME C++ compiler and linker Python is built with...
13
by: SpaceCowboy | last post by:
I recently got into a discussion with a co-worker about using enums across a dll interface. He wanted to use chars instead, argueing that depending on compiler settings the size of an enum could...
1
by: 3f | last post by:
Hello; We have made a web application that people can download from our web site and installed on: Windows XP Windows 2000 Professional Windows 2003 Server Windows 2000 Server
11
by: Arturo DiDonna | last post by:
Hello everyone. I am trying to compile someone else code and I am stuck with compilation problems using the g++ 3.3 compiler. Basically, when compiling the following code, I get this error...
5
by: Ben Bloom | last post by:
I'm new to XSLT, but everything I've read says this is the best approach to solving the XML->CSV problem. Based on some web reading, I came across the following XSLT code which appears valid, even...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
3
by: Andreas | last post by:
Hi! I'm currently developing a DLL that makes use of C++ and .net (mixed) using Visual Studio 2003. Now, as I wanted to move to the new Visual Studio 2005, I converted this project into the...
6
by: msb_6 | last post by:
Currently I have a PHP extension thats all written and compiles under windows, but the PC I'm going to end up putting it on is running Ubuntu 8.04 (g++ 4.2.3). I've delved into PHP documentation...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.