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.
I want to use Open with > Choose another app > More apps > Look for another app on this PC (I'm not worrying about file associations yet - during development this is fine)
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 "%PathOfTheFileIOpened% - KuroNote", which seems to be automatic.
App.xaml
<Application x:Class="KuroNote.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:KuroNote"
Startup="Application_Startup"
ShutdownMode="OnMainWindowClose">
<Application.Resources>
</Application.Resources>
</Application>
App.xaml.cs
namespace KuroNote
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
private void Application_Startup(object sender, StartupEventArgs e)
{
MessageBox.Show("test");
foreach (string s in e.Args)
{
MessageBox.Show(s);
}
}
}
}
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 "Look for another app on this PC" method, I don't even get the "test" message box, like you see is written above.
As you can see from this screenshot of the project properties, the startup object is also set to be the app.
I thought it might be permissions-related, but the executable and the file to be opened are never in protected administrator-only areas.
I've done tests before while debugging, retrieving command line arguments set in project properties > debug tab > "application arguments:", and those are returned just fine. Something seems to be different about opening using the "Look for another app on this PC" method, it's like it's doing more than just launching the app with a command line argument with the filepath.
Am I missing some kind of flag in App.xaml that enables "Open with" functionality?
It's a purely offline application, not a web app, and the files I get after publishing are just "KuroNote.deps.json", "KuroNote.dll", "KuroNote.exe", "KuroNote.pdb" and "KuroNote.runtimeconfig.json", no ".application" files that it sounds like "ClickOnce" uses. If I search for "ClickOnce" inside visual studio, it says I can install it, but it doesn't sound like it's already installed. Unless there's some hidden "use ClickOnce" setting that I need to disable?