18

Firstly I'm completely aware of this message and why it happens normally. It's not that I'm just trying to run a dll (like this question).

I have a project that compiles to a dll but has a startup program specified in the project properties. Most of the time I'm able to right-click on the project and select Debug > Start new instance, and it will run the program and let me debug my dll. However, occasionally I get this message (A project with output type of class library cannot be started directly) as if I haven't got a startup program. The first few times I thought it was just me accidentally clicking on the wrong project but I'm certain this isn't the case given that it's happened so many times and I've been careful to watch it.

When this message appears I'm able to try it again and it always works on the second or third attempt.

A colleague using the same Solution never has this problem :-/

Anyone else had this problem or know how to solve it?

I'm using Visual Studio 2005 Pro Version 8.0.50727.762 (SP.050727-7600) Edit: Also happens with Visual Studio 2010

Community
  • 1
  • 1
Rory
  • 40,559
  • 52
  • 175
  • 261

9 Answers9

11

Another colleague suggested it's because after clicking Debug > Start new instance, while I'm waiting for it to start up, I click on a different project. I don't do it for any reason, just randomly selecting things as I wait for the project to start up. Maybe Visual Studio looks at the selected project sometime after I clicked the menu, gets confused, and shows the error message?

Anyone able to confirm this matches their experience?

Rory
  • 40,559
  • 52
  • 175
  • 261
  • 3
    This problem persists with VS 2010 and I'm 99% sure it's because I'm clicking on a file in a different project. Seems repeatable. Odd. – Rory May 20 '11 at 10:07
  • The same happened to me. After I click my project, I run it perfectly!!! Very strange :/ But it works!!!!! – Sterling Diaz Jul 24 '13 at 09:38
10

Typically problems in VS are caused by:

  • Add-ins: Run VS without and see if the problems is solved
  • Corrupted files in your solution: Delete / rename all files created by Visual Studio which are not part of your project, i.e. all .suo, .ncb files and a like.
Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
  • 4
    +1 for the deletion of the .suo file. That often fixes problems for me (especially with breakpoints that disappear or reappear for no reason.) – Pedro Apr 20 '09 at 19:31
7

I had this problem with projects that were created as "Windows Control Library" that somehow forget their status. Unloading and reloading the project usually did the trick.

If it was created as a "Class Library" then to make it a "Windows Control Library" I manually add the following to the .csproj file. It was the only difference I could see between a class library and windows control library project.

BTW - starting a Windows Control Library starts the User Control Test Container - allows you to test any user control in the library. Very cool.

<Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />

add that inside of an <itemgroup> element.

Shea
  • 11,085
  • 2
  • 19
  • 21
5

If you plan to use/create/add extra dll's or just have more than one project in your solution, you may get this kind of problem, especially if you forgot a simple rule: 1. In your "Solution Explorer" window. Right click and chose "Set StartUp Projects..." 2. Under "Start Up Project" select and change "Single startup project" to your working entity.

Roman Polen.
  • 549
  • 7
  • 10
2

no just make a start up project

2

Going to resurrect this thread, I have just been experiencing similar issues, when right clicking a project and start new instance..

So instead of right clicking the project and selecting start new instance, I right clicked and clicked set as startup project.

Low and behold a class library project was set to bold, certainly not the one I was right clicking.

I tried selecting a different executable project and setting that as the startup project. Same class library was highlighted as the start up project.

Realised that the current open file was from that project, possibly all the open files were from that project...

closed all open files and tried again.... Problem solved, behaviour as expected for both set as start up project and start new instance options...

Definitely a bug, hope this helps others..

  • Microsoft Visual Studio 2010 Version 10.0.40219.1 SP1Rel
  • Microsoft .NET Framework Version 4.0.30319 SP1Rel
Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Alexis Coles
  • 1,227
  • 14
  • 19
0

I've found that I've had the Startup Project on the Solution set to Current selection, then at some point, I've unloaded a project, and the solution has reverted to Single startup project on a project that happens to be a class library.

Reuben
  • 4,136
  • 2
  • 48
  • 57
0

This sounds like a transient Visual Studio problem. Reinstallation or upgrade may solve your problem.

Paul Sonier
  • 38,903
  • 3
  • 77
  • 117
0

I've seen this as well, and it seems like a bug in VS. It happens after you right-click/build a class library (that requires rebuilding), and then right-click/debug > start new instance.

edit- It's still very intermittent, I can't seem reproduce it reliably

efess
  • 91
  • 5