title: C# WPF App silently crashes if I use "open with"
body: <p>I am making a text editor in C# WPF. After publishing the project to a folder, I can double-click the .exe, it runs fine, and I can load files using my Open (CTRL+O) function perfectly fine.</p>
  <p>I want to use <strong>Open with &gt; Choose another app &gt; More apps &gt; Look for another app on this PC</strong>
  (I'm not worrying about file associations yet - during development this is fine)</p>
  <p>Here's the problem - no matter what I do to my code, I can't get my app to do anything useful when I use this method to open it. What happens is it brings up a randomly sized white window and looks like it's busy - after 2 seconds it closes itself. The name of the window is &quot;%PathOfTheFileIOpened% - KuroNote&quot;, which seems to be automatic.</p>
  <p><em>App.xaml</em></p>
  <pre><code>&lt;Application x:Class=&quot;KuroNote.App&quot;
               xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
               xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
               xmlns:local=&quot;clr-namespace:KuroNote&quot;
               Startup=&quot;Application_Startup&quot;
               ShutdownMode=&quot;OnMainWindowClose&quot;&gt;
      &lt;Application.Resources&gt;
           
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  <p><em>App.xaml.cs</em></p>
  <pre><code>namespace KuroNote
  {
      /// &lt;summary&gt;
      /// Interaction logic for App.xaml
      /// &lt;/summary&gt;
      public partial class App : Application
      {
          private void Application_Startup(object sender, StartupEventArgs e)
          {
              MessageBox.Show(&quot;test&quot;);
              foreach (string s in e.Args)
              {
                  MessageBox.Show(s);
              }
          }
      }
  }
  </code></pre>
  <p>As you can see, I removed all the useful code to try and get it to do SOMETHING - I'm not even opening the main window, I just want it to output its command line arguments. When I use the &quot;Look for another app on this PC&quot; method, I don't even get the &quot;test&quot; message box, like you see is written above.</p>
  <p>As you can see from <a href="https://i.stack.imgur.com/Ailkx.png" rel="nofollow noreferrer">this screenshot of the project properties,</a> the startup object is also set to be the app.</p>
  <hr />
  <p>I thought it might be permissions-related, but the executable and the file to be opened are never in protected administrator-only areas.</p>
  <p>I've done tests before while debugging, retrieving command line arguments set in project properties &gt; debug tab &gt; &quot;application arguments:&quot;, and those are returned just fine. Something seems to be different about opening using the &quot;Look for another app on this PC&quot; method, it's like it's doing more than just launching the app with a command line argument with the filepath.</p>
  <p>Am I missing some kind of flag in App.xaml that enables &quot;Open with&quot; functionality?</p>
  <hr />
  <p>It's a purely offline application, not a web app, and the files I get after publishing are just &quot;KuroNote.deps.json&quot;, &quot;KuroNote.dll&quot;, &quot;KuroNote.exe&quot;, &quot;KuroNote.pdb&quot; and &quot;KuroNote.runtimeconfig.json&quot;, no &quot;.application&quot; files that it sounds like &quot;ClickOnce&quot; uses. If I search for &quot;ClickOnce&quot; inside visual studio, it says I can install it, but it doesn't sound like it's already installed. Unless there's some hidden &quot;use ClickOnce&quot; setting that I need to disable?</p>