OfficeDev / Office-Add-in-samples

Code samples for Office Add-in development on the Microsoft 365 platform.
MIT License
745 stars 805 forks source link

Debugging Blazor Addin project #535

Closed RaoulRSV closed 6 months ago

RaoulRSV commented 1 year ago

Debugging a project build on the "Blazor Addin" template gives me hard time.

  1. Break points for C# are not available for C# on the Blazor Addin templates, while you have them on any basic Blazor projects from "Visual Studio/create a project". It is a constraint but you can still get around using console.Writeline("").
  2. Break points for JS are available for JS. But
    • JS changes are randomly not updated (notably on an error but I cannot guarantee) : -- visual basic actually run the previous code -- breakpoints turn from red to yellow (not accessible) and sometimes disappear -- on some conditions (I didn't understand which!) a window named "localhost:7287 [dynamic] appears on the right side with the previous code; this window being readonly.
      • Afterward the project sticks on this previous JS code whatever you try : close the project, reboot machine, empty WEF or Bin folder, hit CTRL F5, activate debug for javascript ...
      • This behaviour expands to the other projects based on this same template that exists on your machine.
      • Changing the launchsettings applicationURL ( 7283, 7287, 7288 and 7289) gives you another try but inevitably you finish to spoil all these avalaible URL.
        • This behaviour desappears after hours or few days but I don't know whether it is spontaneous or due to tries I doing to solve it.

This behaviour seems to worsen with the size of the code. Question I am looking for any suggestion on how to handle this issue and

aafvstam commented 1 year ago

Hi Raoul, while trying to debug your issue(s) I ran into many of the same issues (unable to break on C#, unable to open the Developer Tools on the Task Pane window). I found that starting Visual Studio as Administrator helped and did get my C# to break and open the Task Pane developer tools. Can you try to see if that works for you as wel?

RaoulRSV commented 1 year ago

Hi Maarten, Concerning C# break point : I tried my project and your seminal project as administrator with no success. Concerning "open the Developer Tools on the Task Pane window" I am not sure to understand your point but on my side I didn't discover any problem in accessing developping tools either on visual basic 2022 ou on chrome. Concerning JS debugging : my problems where probably due to a bug in my project. I am still working on it before confirming the point. Sincerly

aafvstam commented 1 year ago

Hi @RaoulRSV With my comment on "Open the Developer Tools on the Taskpane", what I meant is that it was failing for me to right click the Taskpane to open the 'web' developer tools. It gives me a white screen and nothing else, unless I started running the VS Project 'as administrator'. By doing so I got the normal browser developer tools available.

I was thinking, where are your breakpoints? Are they on the pages/scripts that are triggered by the Ribbon, or are they visible in the Taskpane? I think, but need more investigation on that, is that the pages triggered by the Ribbon are in a separate 'session' and therefore not showing up when you hit the breakpoint.

Overall, the debugging experience is not a joy 😉

ghost commented 1 year ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

RaoulRSV commented 1 year ago

Hi Maarten. For me, as a regular user (not administrator), right click/inspect on the taskpane does open the Chrome web devtool for me with no white screen. C# breakpoints tested were placed on the pages/scripts whether it is :

akshayta23 commented 1 year ago

Hi @aafvstam - Could you please help with the query above?

ghost commented 1 year ago

This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!

RaoulRSV commented 1 year ago

Hi Maarten, how is it possible to help?

aafvstam commented 1 year ago

@RaoulRSV I have created a new branch where I'll try to solve/research the items you also mentioned here: https://github.com/OfficeDev/Office-Add-in-samples/issues/535#issuecomment-1607065032

My branch can be found here: https://github.com/aafvstam/Office-Add-in-samples/tree/aafvstam-blazor-addin-commands

Keep you updated ...

davidchesnut commented 1 year ago

Hi @RaoulRSV, I just submitted a PR #596 to ensure the Blazor samples are configured for C# debugging. This may help this issue. Please let me know if you still need any assistance on this issue.

Thanks! David

RaoulRSV commented 1 year ago

@davidchesnut. Thank you for your commitment on this issue. Sure, I am still interested in it

aafvstam commented 9 months ago

Sorry for the late response. Due to some personal events, I wasn't able to respond sooner. I just did a quick test to see if the debugger was working and was happy to see that breakpoints were hit in both CS and JS. This is recorded in my Live Stream. We can have some contact later on to see where your issue occurs. I was using the latest version (Version 17.8.6) and both the Excel and Word project were working, however this obviously is in the original sample code using .NET 6. I will be porting to .NET 8 in the coming week(s) and check if debugging still works there. Let's keep in contact (you already found me on LinkedIn) to get this to work.

Maarten

RaoulRSV commented 9 months ago

@aafvstam Thank you for your answer. I confirm you that now I can also see breakpoints in C# with the Excel-blazor-addin template (from github office-addin-samples-main) with the latest version of Visual-studio 2022 and .NET 6. It occures with an unharmful avertissement from Microsoft-WebAssembly.Diagnostics.Devtools Proxy saying "DotNetDebugger.set Debugger Property 'wasn't found" code -32601 However, with my project I still cannot see breakpoints in C#. This project is derived from the Excel-blazor-addin template with perhaps a previous version and is using .NET 8. I will test .NET 6 in the next days

RaoulRSV commented 9 months ago

@aafvstam I did test the Excel-blazor-addin template with .NET8.0. It failed to run the complement with the following message : "Process with Id26228 was not executed" (Note : this message is my translation from french). The same message eventually mention also "Id2172". I remind having been faced with the same issue when upgrading to .NET8.0 but I don't recall how I did workaround it.

I did also test my project with .NET6.0 : C# breakpoints were similarly not effective.

aafvstam commented 9 months ago

Interesting, I upgraded the Blazor Samples to .NET 8 (8.0.1) yesterday, and I was actually able to see and use the breakpoints in both C# and JS.

The Pull Request has not been approved yet, so you need to go to my Fork to get the code from my PR: https://github.com/aafvstam/Office-Add-in-samples/tree/aafvstam-update-net-8

Can you try to simply clone the repo and hit F5 to build and run?

My YouTube recording is not listed yet (need to do some editing on the properties before publish) but you should be able to follow along here: Live Coding Session 20240201

Let me know what your findings are on the PR code here ...

aafvstam commented 8 months ago

My PR has been approved so the link above is obsolete but debugging should work now and this could be closed.

With things related to JS debugging, I too find this still challenging as often it doesn't update the cache and still runs against 'old' code. What I do here is check in Developer Tools to see if it has the updates, otherwise refresh cache from there and rerun.

aafvstam commented 6 months ago

I think we can close this, from what I have tested it is now working properly.

Also, the item did not get any feedback lately that it was not working, so if not, reopen a new issue referencing this one to follow up and start a new process.