20

Please can someone could explain why I get this error and what to do to fix it (or what I'm doing wrong!). The steps I have taken are

  1. Download Source code from http://www.codeproject.com/Articles/16859/AForge-NET-open-source-framework
  2. Opening in VS2010 shows the references cannot be found enter image description here

  3. Re-Add all 3 references from PlayingCardRecognition\bin\Release so no further warnings enter image description here

  4. When I try and build or Run I get the following message enter image description here

  • 1
    can you try this answer as 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:49

15 Answers15

88

To fix this issue, do these steps:

  1. Right click the Project name in Solution Explorer of Visual Studio
  2. Select Set as StartUp Project from the menu
  3. Re-run your project It should work!

If it did not work, be sure that you have set your start page. If your project is C# Windows Application or C# Console Application, try this:

  1. Right click the Project name in Solution Explorer of Visual Studio
  2. Select Properties
  3. Select the Application tab
  4. In the Output Type drop box
  5. Select the correct application type of your project
  6. Re-run your project and let me know if it won’t work.
AxxieD
  • 614
  • 1
  • 7
  • 28
SRoy
  • 987
  • 2
  • 8
  • 10
  • Bingo! Mak's answer worked for me. It is also much easier than the answer that got the green check mark. – JohnH Sep 08 '16 at 14:01
  • Upvoted. In my case I had a project with unit tests, and VS community was trying to start that instead of the project. I right-clicked the project as above, then selected set startup projects, then clicked on "Single Startup Project" and changed the dropdown to the project name (not the .Tests.) Then I clicked OK and everything worked correctly. – Matt West Dec 06 '16 at 19:21
  • In my case I had one additional hangup that may help someone: I was referencing another project that registered a COM DLL and I had to also (in addition to Sam's comments) change the Platform target of the StartUp Project to match i.e. either x64 or x86 (cannot use any CPU because of the UnmanagedExports package). – ChE Junkie Dec 02 '17 at 05:09
  • Mhm, I don't have the Application tab - I am trying to debug Unity 3D project built in Unity 2018.3.3 and using Visual Studio 2017 Professional Edition. – codeepic Feb 06 '19 at 00:47
11

The project type set as the Start-up project in that solution is of type ClassLibrary. DUe to that, the output is a dll not an executable and so, you cannot start it.

If this is an error then you can do this:

A quick and dirty fix for this, if that is the only csproj in the solution is to open the .csproj file in a text editor and change the value of the node <ProjectGuid> to the Guid corresponding to a WinForms C# project. (That you may obtain from a google search or by creating a new project and opening the .csproj file generated by Visual Studio to find out what the GUID for that type is). (Enjoy - not many people know about this sneaky trick)

BUT: the project might be a class library rightfully and then you should reference it in another project and use it that way.

dutzu
  • 3,883
  • 13
  • 19
9

.Exe's and .dll's are both assemblies. The key difference is that executeables define an entry point Main which can be invoked by the runtime. The error

"Class library cannot be started directly"

is due to the fact that said .dll's do not have a Main. To fix this issue, change the project type to a Windows application/Console application and define an entry point. Or, add a new project that is of type Windows application/Console application and reference said .dll.

P.Brian.Mackey
  • 43,228
  • 68
  • 238
  • 348
3

The project is a class library. It cannot be run or debugged without an executable project (F5 doesn't work!!!). You can only build the project (Ctrl+Shift+B).

If you want to debug the code add a console application project (set it as the start up project) to the solution and add the reference to the library.

Corneliu
  • 2,932
  • 1
  • 19
  • 22
2

The project you downloaded is a class library. Which can't be started.

Add a new project which can be started (console app, win forms, what ever you want) and add a reference to the class library project to be able to "play with it".

And set this new project as "Startup project"

Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122
1

The project you've downloaded is a class library, not an executable assembly. This means you need to import that library into your own project instead of trying to run it directly.

keyboardP
  • 68,824
  • 13
  • 156
  • 205
  • How do you import the library? – nu everest Feb 14 '18 at 16:21
  • I figured it out press CTRL + F5. When compilation succeeds it places a dll in the /bin/Debug folder. Copy and Paste this dll into another project. Right Click project and select "Add Reference" browse to the new dll. – nu everest Feb 14 '18 at 18:02
1

Your project type is a class library one would suspect, add a ConsoleApplication or WindowsApplication and use that as your startup object. Reference this project and then access the code.

LukeHennerley
  • 6,344
  • 1
  • 32
  • 50
1

If you convert the WPF application to Class library for get the projects .dll file.After that convert the same project to the WPF application you get the following error.

Error:".exe does not contain a static main method suitable for an entry point".

Steps to troubleshoot: 1.Include the App.xaml file in the respective project. 2.Right Click on App.xaml file change the build action to Application Definition 3.Now Build your project

0

Goto the Solution properties -> on Build right side you see the startup project type. here you need to select the console appication/windows appication.

0

If you got this issue (got it in Visual Studio 2017 RC), and you don't get any of the things listed by Mak post from step 3 onward "4 In the Output Type drop box....", it is because you made a Class Library app when you want to create a cross platform app, so here is the solution :

1 Start a new project

2 select Visual C# and cross-platform app.

3 select cross-platform app (Xamarin and native app)

4 select blank form.

From then , right click, select as startup project and build as mentioned by Mak, and it should work.

If you can afford to start from scratch, it could do the trick as it did for me.

This could do the trick for the main issue as well, but must be adapted to your current version of Visual Studio ("Xamarin.forms portable" for visual studio 2015 for example).

Bye!

Xorus
  • 1
  • 2
0

VS -> Debug -> Attach unity debugger -> double click project

Koray
  • 373
  • 4
  • 12
0

I had this same error, but I was using a command line instead of visual studios. I needed to add <OutputType>Exe</OutputType> to a PropertyGroup in my .csproj file. (net6.0)

I discovered this by creating a default hello world program, which would run when I use dotnet run in WSL (I don't think this is specific to WSL). To create this default program I used this command in wsl: dotnet new console -o PerformanceTesting2 -f net6.0

And this was the output .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
</Project>

The only thing different for me was the Output Type. Once I changed that dotnet run worked.

Hopefully this helps someone else who had the same problem as me and stumbled on upon this post.

Andy
  • 91
  • 3
-1

Set your api project to a startup project: Right click the api Project than choose Set as startup Project.

Yael
  • 9
-2

Just right click on the Project Solution A window pops up. Expand the common Properties. Select Start Up Project

In there on right hand side Select radio button with Single Startup Project Select your Project in there and apply.

That's it. Now save and build your project. Run the project to see the output.

_Sarath@F1

-4

To fix this issue, do these steps:

Right click the Project name in Solution Explorer of Visual Studio Select Set as StartUp Project from the menu Re-run your project It should work!

Akshay
  • 1
  • 1
  • 3
    This is exact copy of Mak's answer from 4 years ago with poorer formatting, what's the point of repeating it? – niemmi Dec 22 '16 at 14:10