0

We have a Windows Service that runs as Local System. Luckily, I can run it as a normal console application. The application won't execute if we start it as a Current User because it tries to access some certificates that are installed as Local System. So, in order to debug the process, I had to start Visual Studio as Local System with the following command -

psexec.exe -i -s <Visual Studio Path>

And I was able to attach to the process without any issues. But the problem happens when I try to debug it. Once, it hits a breakpoint, I get the Edit and Continue popup with the below message -

Edits were made which cannot be compiled. Execution cannot continue until the compile errors are fixed. Refer to the Error List Window for further details.

But no edits were made to the code, and I didn't find any errors in the Error List Window.

Some Stack Overflow posts suggested disabling the Edit and Continue option in the Visual Studio settings. That seems to be a good workaround, but I would like to know if there are some other good solution to fix this.

Thanks in advance :)

Dhilip H
  • 594
  • 4
  • 10
  • What exact version of VS are you using? I've been seeing the Edit and Continue message popup after *any breakpoint is hit* just debugging normal applications since I updated to latest recently. – Damien_The_Unbeliever Aug 20 '21 at 06:10
  • No, you don't need to run Visual Studio as Local System (I doubt if Microsoft ever supports that either), but just as administrator. Then you can attach to the Windows service process and debug the code. Edit and Continue won't work in that case, as attaching to a process does not match its conditions. – Lex Li Aug 20 '21 at 06:14
  • @Damien_The_Unbeliever I'm using Visual Studio 2019 Professional (Version 16.10.4) – Dhilip H Aug 20 '21 at 07:22
  • @LexLi But when I launch VS as administrator, it still runs as a user with admin privileges, and it's not able to access the certificates installed in `LocalMachine` store – Dhilip H Aug 20 '21 at 07:25
  • 1
    *'certificates that are installed as Local System'* - do you mean, the certificates are in the local machine certificate store? If so, you could give access rights for your normal user and debug normally. I don't think running VS with psexec is a good idea. – Steeeve Aug 20 '21 at 07:25
  • 1
    If you run VS as admin and then attach to a Windows service app running under Local System, in all cases the account to access the certificate is Local System. The account used to run VS and the debugger is irrelevant under that context. https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-debug-windows-service-applications#to-debug-a-service – Lex Li Aug 20 '21 at 08:17
  • Try some of the solutions provided in this thread:https://stackoverflow.com/questions/4782057/edit-and-continue-feature-stopped-working-in-visual-studio-2010 – DanielZhang-MSFT Aug 20 '21 at 08:39
  • Thank you, everyone, for your responses! I managed to achieve my requirement with @Steeeve's suggestion. – Dhilip H Aug 20 '21 at 11:50

0 Answers0