Is there a clean way to access the commandline arguments passed as part of an AppDomain.ExecuteAssembly call that starts a WPF application?
I’m spinning up a WPF application in a separate app domain and passing arguments to the application like so:
AppDomain moduleDomain = AppDomain.CreateDomain("Friendly Name");
moduleDomain.ExecuteAssembly(path, new[] { "arg1", "arg2" });
There’s a work-around to access these arguments, since both Environment.GetCommandLineArgs() and StartupEventArgs return the commandline arguments for the original application, not the one spun up with ExecuteAssembly().
I would like to access the arguments passed to the WPF application without having to manually define a Main method, preferably using StartupEventArgs. Is there a way to do so?
Starting the WPF application in a separate process works, but has performance penalties and complicates debugging.
Tigran’s comment lead me to a solution that I’m happy with, using AppDomain.SetData instead of using command line arguments. The basic outline looks like this:
Then, to access the ‘arguments’ in the WPF app:
This works well for my use case.