32

A project with an output type of class library cannot be started directly. In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

While running the program in C# visual studio 2010 I am getting this error. Please tell me how to sort out this error?

kame
  • 20,848
  • 33
  • 104
  • 159
user1577052
  • 341
  • 1
  • 3
  • 4
  • 5
    The error message tells you exactly what you need to do. What are you having difficulty with, precisely? – J. Steen Sep 06 '12 at 14:02
  • 2
    The project you've attempted to debug can't be debugged because it's a class library so there is no point of execution. Do you have any other projects in your solution? –  Sep 06 '12 at 14:03
  • 1
    Well I think you should post this error... – RvdK Sep 06 '12 at 14:03
  • 1
    @PoweRoy at beginning is the error – Renatas M. Sep 06 '12 at 14:04
  • Can you try this answer, it helped me! http://stackoverflow.com/questions/11152272/a-project-with-an-output-type-of-class-library-cannot-be-started-directly/25843029#25843029 – Jerric Lyns John Sep 15 '14 at 07:48
  • Possible duplicate of ["A project with an Output type of Class Library cannot be started directly"](https://stackoverflow.com/questions/3363106/a-project-with-an-output-type-of-class-library-cannot-be-started-directly) – kenorb Sep 18 '18 at 16:07
  • Possible duplicate of [A project with an Output Type of Class Library cannot be started directly](https://stackoverflow.com/questions/14506185/a-project-with-an-output-type-of-class-library-cannot-be-started-directly) – Nande Jan 22 '19 at 22:32

11 Answers11

68

Set your startproject in the project explorer by clicking right mouseclick on an executable project and choose "Set as start project"

CloudyMarble
  • 36,908
  • 70
  • 97
  • 130
21

You created the project as a class library project, not an executable program. Class libraries are compiled and then used by other applications for common functionality.

If you meant to create a class library, you need to create a test application (or, better yet, Unit Tests) to test the functionality. If you meant to create an executable application, you'll need to modify the project.

If you have multiple projects in a single solution, you might also need to make sure you have the correct project set as the "Start Project" rather than one of the class library projects.

Justin Niessner
  • 242,243
  • 40
  • 408
  • 536
10

what you have done is that you have made a class library with all your code
every project in .Net needs a starting point like Main() function in c# which obsly isnt present in a class libraty type of project
what you can do instead is
1. Make a console project inside the same solution. by right clicking the solution and add new project
2. Add a reference to the class library
3. Access the classes/methods of the class library and then starting the console project instead of class library project

Alternatively,
If you have a console project OR any other project in the solution already
right click the project in the solution explorer and Set as Startup project

Muthu Ganapathy Nathan
  • 3,199
  • 16
  • 47
  • 77
Parv Sharma
  • 12,581
  • 4
  • 48
  • 80
  • I think he may of just not set the startup project. This is stored locally so if he just code the sorce code from someone else it would not be set. – AnthonyLambert Sep 06 '12 at 14:11
  • @AnthonyLambert-really you would downvote for something like this. when this isnt even mentioned in the question? since when giving more(probably correct) info is a reason to down vote – Parv Sharma Sep 06 '12 at 14:14
  • This answer is hard to read and has a lot of formatting problems. That is probably why it got a downvote. – John Koerner Sep 06 '12 at 14:29
  • Tried to set current project(code generated from the class diagram) as an executable project and did not have any luck. Follow @ParvSharma solution, and it works perfectly! – jayko03 Feb 12 '18 at 02:51
5

Right click on Solution-->Go to properties-->Expand Common properties tab-->(On right side) Select Radio button with option Single startup project-->choose project from drop down list.
Enjoy.

Rahman
  • 330
  • 1
  • 7
  • 24
4

If you want to debug code in the DLL or run it using tests, go to the properties of the project, go to the Debug tab, select "Start external program" and enter the name of the application to use, such as a test runner.

akton
  • 14,148
  • 3
  • 43
  • 47
2

Go to your project properties page, change Output Type to Console Application or Windows Application (depending on what it is).

Make sure that you've got correct project set as startup one (right click -> set as startup project), and that this one is not of type Class Library. If your only project in solution is class library, then you need to create some test executable for it.

Bartosz
  • 3,318
  • 21
  • 31
1

The same error type i have found in my one of project suddenly which is running in VS 2012 with MVC 4 only. I have run multiple ways to resolve this error, but i have found filly with small change option in Property window of your respective error giving project. I have went project property window there i have change startup Project from Healpars to Myproject.Then it is working fine. Thank you

1

I was surprised to learn that you can indeed set some Class Libraries as Startup and run them, IF they contain user controls. They run in the UserControl TestContainer which allows one to modify properties, etc. Basically debug at DesignTime, which can be really helpful. I have about 20 user controls in a single Project. This way I can run the TestContainer and choose which user control to run and debug.

beanmf
  • 493
  • 5
  • 7
0

If it is a function app project that you want to execute then you need to have Azure development tool installed in your visual studio. Please see the below image for more info.

enter image description here

0

You need to mark the API in the set as startup project Right key on the API

Liel
  • 1
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 13 '22 at 06:37
  • Try to get into your project And mark the API in the set as a right-key activation project in the API This should be able to undo the error – Liel May 25 '22 at 18:36
-3

select .net core project, then it will start directly with no doubt. Thanks