Cannot select Main Method as Startup object in Visual Studio Express 2010?

Viewed 19556

I have written a Main method in one of my classes. My startup Object says Not set. When clicking on it nothing else shows in the dropdown menu. Why can't I select the main method to be my Startup Object? I want to run my Main Method only by pressing ctrl+F7 but when doing so, nothing happens. Below is the very short Main method that I am using.

static void Main(string[] args)
{
    Program c = new Program();
    c.consoleread();
}
7 Answers

If the class that you want is not showing up in the drop down, you can double click on the project in the Solution Explorer and add the class name after the project name. (shown in code as "myproject" and "myclass")

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<StartupObject>myproject.myclass</StartupObject>
</PropertyGroup>

</Project>

If your project uses the "Enable application framework" option, that would be one possibility why Sub Main is not shown.

From https://visualstudiomagazine.com/articles/2007/10/01/enable-the-application-framework-in-vb.aspx

Q What happens when I check "Enable application framework" in my Visual Basic application? Why does my Sub Main disappear from the Startup Object dropdown...

A Visual Basic supports an "Application Framework" that makes it easier to manage the startup, shutdown, and exception management of an application. You enable or disable the application framework with a check box in the Project Properties. ...

Whether or not you use the Application Framework, Visual Basic generates a hidden My.Application class for your application. ...

The part of the My.Application class that you can't see includes a shared Sub Main as the entry point of the application. ... The reason Sub Main disappears from the startup combo box is that Visual Basic is supplying Sub Main for you.

That's just a summary of the most relevant aspects for this question but the linked article also includes some other details explaining the application framework.

Related