title: Passing Command Line Arguments from VB to C# WPF Application
body: <p>I have a C# WPF application which I want to be able to open from another existing application, which was written in VB.net. As far as the c# application goes, I think I know how to get command line parameters that are passed to it two different ways, which I got while researching google and using others' answers.</p>
  
  <p><strong>App.xaml Header</strong></p>
  
  <pre><code>&lt;Application x:Class="ChallengeHandler.App"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
           xmlns:local="clr-namespace:ChallengeHandler"
           Startup="Application_Startup"&gt;
  </code></pre>
  
  <p><strong>App.xaml.cs Method 1</strong></p>
  
  <pre><code>    private void Application_Startup(object sender, StartupEventArgs e)
      {
          string[] args = Environment.GetCommandLineArgs();
          if (args.Length &lt; 1)
          {
              MessageBox.Show("No parameter provided. Failed to run.");
              Shutdown();
          }
          else
          {
              MainWindow wnd = new MainWindow(args[0]);
              wnd.Show();
          }
      }
  </code></pre>
  
  <p>The above method will result in the application opening but none of the data, which relies on the parameter, is populated. So the comboboxes and stuff in the views are just empty. That fails.</p>
  
  <p><strong>App.xaml.cs Method 2</strong></p>
  
  <pre><code>    private void Application_Startup(object sender, StartupEventArgs e)
      {
  
          if (e.Args.Length &lt; 1)
          {
              MessageBox.Show("No parameter provided. Failed to run.");
              Shutdown();
          }
          else
          {
              MainWindow wnd = new MainWindow(e.Args[0]);
              wnd.Show();
          }
      }
  </code></pre>
  
  <p>This method just shows the error messagebox each time, as the args is empty.</p>
  
  <p>I have a feeling the issue is when I'm trying to open the application from the VB.NET application and pass the string parameter to the c# app from there. But I am out of ideas on how to pass a string like a command line parameter from the VB.net code.
  <strong>Calling from a VB.net Application</strong></p>
  
  <pre><code>    Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\Microsoft\ChallengeHandler.appref-ms"
      Dim pHelp As New ProcessStartInfo
  
      If System.IO.File.Exists(sPath) Then
          pHelp.FileName = sPath
          pHelp.Arguments = "097"
          pHelp.UseShellExecute = True
          pHelp.WindowStyle = ProcessWindowStyle.Normal
          Dim proc As Process = Process.Start(pHelp)
      End If
  </code></pre>
  
  <p>I have tried the VB code without the </p>
  
  <pre><code>pHelp.UseShellExecute = True
  pHelp.WindowStyle = ProcessWindowStyle.Normal
  </code></pre>
  
  <p>with no avail; I added them in the hope the shell execute would force the parameters as command line parameters. I have also tried this in VB:
  <strong>2nd VB Method</strong></p>
  
  <pre><code>    Dim sPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Programs) + "\Microsoft\ChallengeHandler.appref-ms"
      If System.IO.File.Exists(sPath) Then
          System.Diagnostics.Process.Start(sPath, "097")
      End If
  </code></pre>
  
  <p>Any insight would be GREATLY appreciated! Thanks.</p>