By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,401 Members | 803 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,401 IT Pros & Developers. It's quick & easy.

problems compiling first Windows application

P: 93
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
Share this Question
Share on Google+
1 Reply


vekipeki
Expert 100+
P: 229
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

Post your reply

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