Skip to content

Commit

Permalink
Update debugging-previewer.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Takoooooo authored Jul 23, 2023
1 parent 9aeb448 commit a4c60d1
Showing 1 changed file with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,16 @@ Then you click "Attach with .NET Core Debugger" and after that by using "Search

**Debugging with Visual Studio**

You may try to attach the debugger manually. For doing that you will need to find a previewer process. You may use e.g "Process Hacker". Here you will see all processes in the system. Everything you will need to do is to type Avalonia in the search field.
To start debugging you would need a process ID. To get it you need to switch the output to Avalonia Diagnostics. Then you copy the number before the "Connection initialized" message. This number is the previewer process ID.
![image](https://github.com/AvaloniaUI/avalonia-docs/assets/53405089/0b77cb87-2454-458e-9722-0659525feeb9)

<div style={{textAlign: 'center'}}>
<img src="/img/guides/developer-guides/debugging-previewer/132685500-1807dd51-b34c-47ea-b9dd-b1756189c620.png" />
</div>

In my case process was called **.NET Host**. You can understand that this process is Avalonia Previewer by clicking with the right mouse button on the process and selecting "Properties".Here in the "Command line" field, you will see a command that invokes previewer.
Then you may find process by the process id in the process explorer or some other program and attach the debugger manually.

![image](https://github.com/AvaloniaUI/avalonia-docs/assets/53405089/2c50bf8d-047c-481c-af01-00474acc73fe)

<div style={{textAlign: 'center'}}>
<img src="/img/guides/developer-guides/debugging-previewer/132685764-7feff643-8c86-4095-bdad-0d168e435ac4.png" />
</div>

When you know the process id you can simply click "Debug" in process explorer. But sometimes previewer process may crash even before you would attach your debugger. Then you will need to modify this file [Program.cs](https://github.com/AvaloniaUI/Avalonia/blob/master/src/tools/Avalonia.Designer.HostApp/Program.cs) specifically method Main\(one of them depending on target framework\).
When you know the process id you can simply click "Debug" in process explorer. But sometimes previewer process may crash even before you would attach your debugger. Then you will need to add this code th the Main method in the Program.cs.

```csharp
Debugger.Launch();
Expand All @@ -42,6 +39,8 @@ while (!Debugger.IsAttached)

This code will attach debugger to the previewer programmatically.

But if you need to place breakpoints in the previewer code you may need to use [dnSpy](https://github.com/dnSpy/dnSpy) or something similar because Visual Studio doesen't support that.

**How would I understand that I have launched a debugger?**

You should see a window like this.
Expand Down

0 comments on commit a4c60d1

Please sign in to comment.