1

I have a Windows Service Project I created. When the service turns on I use

Debug → Attach to Process

It starts off showing that Symbols haven't loaded so I go into

Windows → Modules

And manually load Symbols. I am able to get the break point to hit but when I hit F10 to step through the code, it is skipping over large amounts of code and not stepping through. Does anyone know why this is happening? Is it because of the work around I am using to load symbols?

Update: I have a DLL I wrote in C#. When the code steps into that DLL it works totally fine and has no problem stepping in and out appropriately. But in the windows service itself it seems to be jumping over large amounts of code.

Update 2 Sorry if I wasn't clear. The Windows Service is one that I wrote. All other window services I have work fine without this issue. I have been able to successfully do it without using F5 but its this particular Windows Service that is not stopping on every break point. When I step into code that is in another dll it breaks properly and everything works. Could it be somehow this project got corrupted?

When I try to debug using F5 this is the message I get

logixologist
  • 3,694
  • 4
  • 28
  • 46
  • Why are you attaching to a process rather than running the program directly with the Visual Studio debugger? – gunr2171 Jul 20 '21 at 14:31
  • @gunr2171 it is a windows service. You cant run it directly. The only way I understood to debug is to start the service and then attach to the process. – logixologist Jul 20 '21 at 14:33
  • 1
    It depends on the Windows Service framework you're using. More or less you just detect if a debugger is running and do something slightly different: https://stackoverflow.com/questions/2255335/how-to-runf5-windows-service-from-visual-studio – gunr2171 Jul 20 '21 at 14:35
  • It's not clear if the Windows service you talk of is one that you have a project/code for or if it is one that is outside of your control. If the former, as the comments suggest, it would be better to start it as a console app when debugging directly with F5 rather than attaching. Perhaps posting more info would get you a better answer. – Kit Jul 24 '21 at 15:59
  • 1
    Ok, knowing the service is in your control, have you tried any of these 1) F5 debug it by setting the start command to NET START , 2) writing code to start your executable, not as a service, but as a console app, and then F5 debug? For case #1, I would expect it may help to set options to embed symbols into the EXE and to build in Debug mode *before* the service is installed. – Kit Jul 27 '21 at 17:28
  • Usually, to debug, I create another class to run with F5. But you may also check if you have the PDB files and your project flags, like if the code is optimized and if it's configured for full build (to generate the PDB). – heringer Jul 28 '21 at 13:00

3 Answers3

1

Please refer Why does F10 (step over) in Visual Studio not work? In order to enable the debug of the unmanaged part the property of the managed project (the startup project) should be set:

Configuration Properties -> Debugging -> Enable Unmanaged Debugging = TRUE;
RajM
  • 21
  • 5
1

Please refer to MS docs for this https://learn.microsoft.com/en-us/dotnet/framework/windows-services/how-to-debug-windows-service-applications#to-debug-a-service

In addition to this, you can also use logs to read and note all the progress. where actually code is.
And I personally prefer logs for windows service debugging

It Says

  1. To debug a service Build your service in the Debug configuration.

  2. Install your service. For more information, see How to: Install and Uninstall Services.

  3. Start your service, either from Services Control Manager, Server Explorer, or from code. For more information, see How to: Start Services.

  4. Start Visual Studio with administrative credentials so you can attach to system processes.

  5. (Optional) On the Visual Studio menu bar, choose Tools, Options. In the Options dialog box, choose Debugging, Symbols, select the Microsoft Symbol Servers check box and then choose the OK button.

  6. On the menu bar, choose Attach to Process from the Debug or Tools menu. (Keyboard: Ctrl+Alt+P)

    The Processes dialog box appears.

  7. Select the Show processes from all user's checkboxes.

  8. In the Available Processes section, choose the process for your service, and then choose Attach.

     Tip: The process will have the same name as the executable file for your service.
    
  9. The Attach to Process dialog box appears.

  10. Choose the appropriate options, and then choose OK to close the dialog box.

     Note: You are now in debug mode.
    
  11. Set any breakpoints you want to use in your code.

  12. Access the Services Control Manager and manipulate your service, sending stop, pause, and continue commands to hit your breakpoints. For more information about running the Services Control Manager, see How to: Start Services. Also, see Troubleshooting: Debugging Windows Services.

Syed Umer Hasan
  • 644
  • 7
  • 11
0

After hours of trying different suggestions. I did not realize it was in Release Mode so it was not loading the Symbols. The link that @RajM shared actually had one user commenting on this and thats how I found out.

logixologist
  • 3,694
  • 4
  • 28
  • 46