title: Process.Start fails and claims "The directory name is invalid."
body: <p>We have a .NET application starting Microsoft Word explicitly with System.Diagnostics.Process.Start, e.g. &quot;C:\PROGRA~2\MICROS~1\Office14\WINWORD.EXE&quot; - the value is retrieved from the registry beforehand (see GetWordExePathFromWindowsRegistry method in the code below). Since we moved from .NET Framework 4.x to .NET Core 3.1, a runtime error in the Process.Start line is thrown: Win32Exception: &quot;The directory name is invalid.&quot; (in our case the German message &quot;Der Verzeichnisname ist ungültig.&quot;) We log the error, and when we open the logged directory in the file explorer, everything is fine; so as far as we can see the error message is not correct.
  This error occurs not always, but often. Sometimes, it helped restarting the application, sometimes restarting the computer. Sometimes nothing helps. Some users get the error more often than others. Users on another site don't have the problem at all. Yet we have no idea what the cause could be.</p>
  <p>Please note that this has been productive code for several years without an issue, and we get the error reports since we moved from .NET Framework to .NET Core 3.1 without this code being changed.</p>
  <p>Here is the code of how we get the path to winword.exe:</p>
  <pre><code>public static string GetWordExePathFromWindowsRegistry()
  {
      Regex exePathRegex = new Regex(
          @&quot;.*\\winword.exe&quot;,
          RegexOptions.IgnoreCase);
      foreach ( string wowNodeName in new[] { &quot;&quot;, @&quot;Wow6432Node\&quot; })
      {
          foreach (string theKeyFormat in
              new[]
              {
              @&quot;SOFTWARE\{0}Microsoft\Windows\CurrentVersion\App Paths\Winword.exe&quot;,
              @&quot;SOFTWARE\{0}Classes\WordDocument\protocol\StdFileEditing\server&quot;,
              @&quot;SOFTWARE\{0}Classes\Word.Document.14\protocol\StdFileEditing\server&quot;
              })
          {
              RegistryKey rootNode = Registry.LocalMachine;
              string keyPath = string.Format(theKeyFormat, wowNodeName);
  
              // Get default registry Value:
              using RegistryKey key = rootNode.OpenSubKey(keyPath);
              string fullWordPath = key?.GetValue(&quot;&quot;)?.ToString();
  
              if (!string.IsNullOrEmpty(fullWordPath))
                  if (exePathRegex.IsMatch(fullWordPath))
                      return fullWordPath;
          }
      }
      throw new Exception(&quot;Path to Word not found&quot;); ;
  }
  </code></pre>
  <p>And then we start Word with something like that (in our case hidden==true because a VSTO add-in in Word does the real stuff):</p>
  <pre><code>public void StartMsOfficeAppExe(
      string msOfficeAppExePath,
      string startArguments,
      bool hidden)
  {
      ProcessStartInfo startInfo = new ProcessStartInfo(
          msOfficeAppExePath,
          startArguments)
      {
          UseShellExecute = false // without this Hidden would not be allowed
      };
      if (hidden)
          startInfo.WindowStyle = ProcessWindowStyle.Hidden;
      Process.Start(startInfo);
  }
  </code></pre>