Reputation: 6429
I have created a simple test solution consisting of 3 projects:
Here is the source code:
public interface ITest
{
void DoSomething();
}
----------------------------------------------
public class Test : ITest
{
public void DoSomething()
{
Console.WriteLine("I've done something...");
}
}
----------------------------------------------
static class Program
{
[STAThread]
static void Main()
{
String[] files = Directory.GetFiles(Directory.GetCurrentDirectory(), "LibraryTest.dll");
Assembly assembly = Assembly.LoadFile(files[0]);
Type typeToStart = null;
foreach (Type t in assembly.GetTypes())
{
if (t.GetInterfaces().Contains(typeof(ITest)))
{
typeToStart = t;
}
}
ITest test = (ITest)Activator.CreateInstance(typeToStart);
test.DoSomething();
Console.WriteLine("Finished");
}
}
In the LibraryProject with the Test class, I reference the forms application project and in the projects properties under Debug, I chose "Start external program" to start the forms application from the libraries debug folder:
As expected, I can now run the library project. This starts the forms application as an external program from within the output folder. There, the forms find the library dll and dynamicall load it and executes the DoSomething method on my Test class.
However, and this is my problem/my question, I don't get any console output in Visual Studio. I can perfectly fine debug the forms application when I run the library project but the console output never shows up. When I use a console application instead of a forms application, an external cmd is opened and I can see the output there but I need the output to also work with forms AND it has to be in Visual Studios output window.
Do you have an idea how I can't see the output? One way I figured out to get an output is to use Trace.WriteLine instead of Console.WriteLine but I don't undersastand why trace works while console doesn't. Any help is appreciated.
Upvotes: 0
Views: 854
Reputation: 28
When you're using forms, it'll disable the console window. If you want to see the output, you'll need to manually enable it.
How do I show a console output/window in a forms application?
Upvotes: 0