Title:
Problem running EXE with Windows Forms via Process.Start() in DLL loaded dynamically by Console application (C#, .NET Framework 4.5.2)
Description:
I am developing a Console application in C# (.NET Framework 4.5.2) that dynamically loads a DLL (also developed by me) using Reflection. Inside this DLL, there is a method that uses Process.Start()
to run an EXE file that contains a Windows Forms interface. However, when I call this method via Reflection, the EXE starts, but the Windows Forms interface does not appear.
Console Program Code:
// Example of the code that loads the DLL
Assembly assembly = Assembly.LoadFrom("MyDLL.dll");
Type type = assembly.GetType("MyNamespace.MyClass");
MethodInfo method = type.GetMethod("MyMethod");
object instance = Activator.CreateInstance(type);
method.Invoke(instance, null);
DLL Code (relevant snippet):
public class MyClass
{
public void MyMethod()
{
// Processing before starting the EXE
var startExe = new ProcessStartInfo();
startExe.FileName = "PathToMyExecutable.exe";
startExe.Arguments = ""arg1" "arg2" "arg3"";
startExe.WindowStyle = ProcessWindowStyle.Hidden;
startExe.CreateNoWindow = true;
Process.Start(startExe);
}
}
The Problem:
- The DLL code is executed correctly (I verified with log messages), the executable starts, but the EXE’s window with the Windows Forms interface does not appear when the method is called via Reflection by the Console program.
- I don’t receive any exceptions or errors, the window simply doesn’t show up.
What I’ve tried:
- I’ve researched several solutions, and some mention using
ProcessStartInfo
withUseShellExecute
orCreateNoWindow
options, but it didn’t solve the issue. - I tested calling the EXE outside the Reflection scenario (directly from another context), and the EXE’s Windows Forms interface shows up normally.
- I also tested loading the same DLL from a non-.NET program (e.g., C/C++), and the EXE and its window appear correctly, so I suspect the issue is related to using Reflection in the Console application.
Constraints:
- The Console project cannot have a direct reference to the DLL. The DLL is loaded dynamically via Reflection.
- The Console application should not have prior knowledge of the DLL or the EXE.
Question: Is there any limitation or specific configuration when using Process.Start()
in a DLL loaded via Reflection that would prevent the EXE’s window with Windows Forms from appearing? How can I ensure the EXE runs correctly and its window is displayed?
Additional information:
- .NET Framework 4.5.2
- The DLL is loaded, and its methods are executed without errors, the EXE is started, but the Windows Forms window doesn’t appear.
- I’ve already tried setting
ProcessStartInfo
with various options likeUseShellExecute = true
,WindowStyle = ProcessWindowStyle.Normal
, without success.
Thanks in advance for your help!
2