Today I am working on my Image Portray App, and I get my code blown up. The problem is, when the App is already started, it can open .ink file with double click from a file. But when the App is not launched, opening a .ink file to start the App will make it crash. As other UWP that supports file type association, I also use OnFileActivated event to launch my App.

This kind of problem could not be debugged in a triditional way, because you can not find your App's process because it is not running, and you can't make Visual Studio attach to it. If you try to start your App from Visual Studio, you can not reproduce the problem.

Well, the truth is, Visual Studio acutally can run debug against an App that is not currently started, and VS debugger will hide in the darkness to observe if the App is started, when the App starts, VS will attach to it's process right away. 

First, you need to copy the pacakge name of you App. It can be found in your App's manifest file:

Then, choose DEBUG -> Other Debug Targes -> Debug Installed App Package...

In the filter textbox, paste in the package name you just copied, and then you can select your App.

Now, make sure you select "Do not launch, but debug my code when it starts"

Then click "Start" button, Visual Studio will now hide himself in the darkness, you can launch your App now.

For my case, by double clicking a .ink file, Visual Studio will attach to the App process right away, and directly hit the exception point.

That's how it's done!