How to debug the .NET Windows Service OnStart method?

后端 未结 16 1317
离开以前
离开以前 2020-12-01 00:13

I have code written in .NET that only fails when installed as a Windows service. The failure doesn\'t allow the service to even start. I can\'t figure out how I can step int

16条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 00:31

    As others have pointed out, you have to add a debugger break to the OnStart-Method:

    #if DEBUG
        System.Diagnostics.Debugger.Break()
    #endif
    

    Also start VisualStudio as Administrator and allow, that a process can automatically be debugged by a different user (as explained here):

    reg add "HKCR\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}" /v AppIDFlags /t REG_DWORD /d 8 /f
    

    (I also explained this here: https://stackoverflow.com/a/35715389/5132456 )

提交回复
热议问题