Do something very different. Don't move any files or add anything. Do the following:
- If you want to preserve your existing application project(s) and solution (always a good idea), make a full copy of it to a different location not changing anything. Make sure it compiles and works.
- Go to project Properties, first tab, change "Output Type" from "Windows Application" to "Class Library". This already will give you a DLL. (Remember, in .NET, the difference between "EXE" and "DLL" is very minor.)
- You got a class library assembly. For this assembly, entry point (static method
Main
) is totally redundant. Remove it, and remove all code which is needed only for the purpose or executing this part of code. Don't remove your form(s) and code related to their functionality. - Review your code for access modifiers. Remember that the purpose of your assembly is to be used in other assemblies, and other assemblies, to access the methods and members with need
public
and protected
access modifiers. (I don't mention reflection here; it would access anything regardless of access modifiers. Let's talk about the access through referencing assemblies.) Don't give more access than it is really required. - Now you need to test your library code with some application. Create a brand new Windows Forms application. If you want to use some form from your library as the main form of this test application, remove its main form and the code depending on it.
- Add the reference to the library to your test project. It's the best to have them in the same solution and use reference by project (the tab "Projects" in the "Add Reference" window). For the main form of new application, use one of the forms of your library (if possible; if this is not the purpose, create forms on some events, like button or menu item clicks on existing form). Test all you need, fix the problems.
- Finally refactor your library project with your test project, keeping in mind its purpose as the library. It may need more adequate names, structure, preparations for adding abstraction. This is a very informal item; you will need to use your own common sense and understanding the the project purpose.
- Use your library in your real application project(s), in the same solution. One of the ways to do it is to re-work your test application to be used as the working application prototype.
- PROFIT!
This way is much, much smoother than the one you have tried. It completely eliminates the problem you have described, because you never do any "dangerous" steps and do one step at a time.
Now, a word of the difference between "EXE" and "DLL". The real difference is just the name and the entry point in "EXE". You can really reference "EXE" in exact same was as it would be a library. It perfectly works and has some real-life uses. From the other hand, you can create a special host which will load and use either DLLs or EXEs as applications; and example of such architecture would be some plug-in architectures.
—SA