Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Error CS5001 while compiling, i have no idea! (http://www.programmingforums.org/showthread.php?t=11682)

aff1993 Oct 24th, 2006 6:36 PM

Error CS5001 while compiling, i have no idea!
 
Hello,
I am new to C# so please dont reply using confusing language, i have made a program but everytime i debug i get 1 error saying:

Build started.
Compiling IconEditor
error CS5001: Program 'c:\Documents and Settings\Tony\My Documents\SallyIDE C#\Sally IDE Source Code\IconEditor\obj\Debug\TestProject.exe' does not contain a static 'Main' method suitable for an entry point
Build failed.

Now, the area where i believe code is is here:



public class MyApplication
{
public static MainForm MyMainForm=null;
private static string moduleDir="";
[STAThread]
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.DoEvents();
moduleDir=Path.GetDirectoryName(Application.ExecutablePath);
MyMainForm=new MainForm();

if (args.Length>0)
{
string ext=Path.GetExtension(args[0]).ToLower();
if (ext==Globals.ProjectExtension) MyMainForm.LoadProject(args[0]);
else if (ext==Globals.SolutionExtension) MyMainForm.LoadSolution(args[0]);
}
Application.Run(MyMainForm);
}
public static string ModuleDir {
get {
return moduleDir;
}
}

}






I dont know how to fix it i just need some help, if you need anymore code, or if you could be really nice and take my source and fix it, that would be great, just message me. Thanks:banana:

DaWei Oct 24th, 2006 6:58 PM

Please read the forum's rules/FAQ, particularly with regard to the use of code tags. It's the polite thing to do when you join a community to ask for help.

Samuaijack Oct 24th, 2006 8:28 PM

>>>Application.Run(MyMainForm);

try entering new before MyMainForm:
Application.Run(new MyMainForm());

Arevos Oct 25th, 2006 4:28 AM

That's not it, Samuaijack. MyMainForm is an reference to an object, rather than a class.

It would help if the author used code tags, but I don't see anything wrong with the program itself. I suspect something is wrong with the configuration of aff1993's IDE.

My advice would be to try and first get a simple Hello World console program compiling, and then move on from there.

Infinite Recursion Oct 25th, 2006 8:57 AM

There a reason you have a space (Execut ablePath) in this line?

moduleDir=Path.GetDirectoryName(Application.Execut ablePath);

Or is that just how it posted in for some reason?

Arevos Oct 25th, 2006 2:02 PM

Probably how it was posted. The forum software splits up continuous sequences of characters longer than 50 characters. Also, the error raised by the compiler doesn't appear to indicate a syntax error.

Infinite Recursion Oct 25th, 2006 3:14 PM

Thnx Arevos, it was just something that caught my attention off hand... odd how the forum software does that. :|

coldDeath Oct 25th, 2006 3:46 PM

I think its to stop the page streching.

Maybe it doesn't split words up in code tags.

peace_of_mind Oct 25th, 2006 4:00 PM

Quote:

Originally Posted by coldDeath (Post 117518)
I think its to stop the page streching.

Maybe it doesn't split words up in code tags.

If he had used them, we'd know the answer. ;)

moduleDir=Path.GetDirectoryName(Application.ExecutablePath); (So we'd know if the OP put the space in or not. I took the space out before posting.)

pal Oct 25th, 2006 4:49 PM

This should run, it will pop up a window, and print out the application path on the command line.
I wasn't sure what the codes that I commented were suppose to do...

:

using System;
using System.Windows.Forms;
using System.IO;

public class Exercise : System.Windows.Forms.Form {

    // Application's path
    private static string moduleDir = "";

    // Application instantiation
    private static Exercise MyMainForm = new Exercise();

    // Set and return a directory path in moduleDir variable
    public static string ModuleDir {
        set {
            moduleDir = value;
        }
        get {
            return moduleDir;
        }
    }

    [STAThread]
    public static void Main(string[] args) {

        Application.EnableVisualStyles();
        Application.DoEvents();

        ModuleDir = Path.GetDirectoryName(Application.ExecutablePath);
        Console.WriteLine(ModuleDir);

        if ( args.Length > 0 ) {
            string ext = Path.GetExtension(args[0]).ToLower();
            Console.WriteLine(ext);
            //  if ( ext == Globals.ProjectExtension )
            //        MyMainForm.LoadProject(args[0]);
            //    else if ( ext == Globals.SolutionExtension )
            //        MyMainForm.LoadSolution(args[0]);
        }

        Application.Run(MyMainForm);

    }
}



All times are GMT -5. The time now is 1:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC