1

I have an assignment about OOP in C# that involves me creating a base class (in the form of a class library) and a derived class (as another class library). I realize that for the two to function properly I need to reference the base class' .dll in the derived class. However, I am unable to generate that .dll file for the base class, as I get the error "A project with an Output type of Class Library cannot be started directly". My textbook says the fix for this is to click "Build Solution" in VS 2013, which should make it runnable. I've done so, and yet mien still does not function. Where am I going wrong?

A B
  • 37
  • 1
  • 1
  • 10
  • The error is telling you that you can't *execute* a class library. Which, well, you can't. It's not an application, just a library of code to be *used* by an application. All you need to do is add a project reference from your derived class' project to your base class' project. – David Apr 26 '15 at 00:43
  • You have to reference the project that contains the base class in the project that contains the derived class. If both class libraries are in the same solution then right click on "Add Reference" and add the class library of the base class to the class library of the derived class. – Jonathan Kittell Apr 26 '15 at 00:43
  • A `.dll` is not a program that you can run. You will need to add a new project to your solution, that will generate an executable application. The easiest would be to select a Console application project. Add references to both of your class libarires to that project and select the project as the one to be run. – Alex Apr 26 '15 at 00:43
  • @David Yes, I understand that I need to reference library 1 in library 2 with library1's .dll file. My issue is that I can't find the .dll file anywhere, and my textbook makes it sound like I need to build/run the first class library to obtain it. – A B Apr 26 '15 at 00:47
  • @AB: If both projects are in a solution in Visual Studio then I wouldn't recommend adding a reference to the DLL. Add a "Project Reference" instead. The DLLs will be in the output folder when you build an application that references those projects. – David Apr 26 '15 at 00:49
  • No, they're separate solutions, and I've finally found the aforementioned .dll file. For some reason it didn't come up in a Windows Explorer search of the folder. – A B Apr 26 '15 at 00:51
  • 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:13

1 Answers1

2

"A project with an Output type of Class Library cannot be started directly"

This means that you are trying to run a project marked as a library, not just build it. Just compile this project without trying to run it, and create another project that is runnable (e.g. console app, win forms app, etc) and reference your current solution from that new project.

Alternatively, change the type of the current project to one that is runnable.

Eric J.
  • 147,927
  • 63
  • 340
  • 553
  • Right, I presumed that's how I would go about obtaining the .dll file to reference in the other class library. I'm not trying run a project yet, I just want the .dll file to put into another class library. This is the page from the textbook I'm using: http://preview.tinyurl.com/l3nlypg – A B Apr 26 '15 at 00:46
  • The error message says you are trying to run the DLL project. – Eric J. Apr 26 '15 at 00:47
  • It's because I was unable to find the .dll file itself and thought that by building/running the project, the file would be generated. I've found it now. – A B Apr 26 '15 at 00:50