7

After I installed Windows 8 perfectly legit statement like this doesn't work anymore:

#if DEBUG
    Debugger.Launch();
#endif

Service starts ignoring that thing. Yes, I am building the project in a debug mode.

if I change that to a Debugger.Break() - the service just fails, and still there's no dialog for attaching a debugger.

iLemming
  • 34,477
  • 60
  • 195
  • 309
  • Is it possible the debugger is already attached? Also, are you demanding the correct permission? See http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.launch.aspx – JP Alioto Aug 20 '12 at 20:16
  • yeah, right. I still can put something like `RequestAdditionalTime(10000);` and attach debugger manually. But in Win7 on `Debugger.Launch()` it would popup a window where you can say I want to attach this instance of VS, however in Win8 it skips that. Why exactly it does that I'm trying to understand – iLemming Aug 20 '12 at 20:34

3 Answers3

13

The secret lies in changing the registry key for the Visual Studio JIT debugger via the following:

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

Before making this change the value on my machine was 0x28. The above changes it to 0x8. In essence it removes the 0x20 flag.

If you search the Microsoft include files (WTypesbase.h) then you find the following:

#define APPIDREGFLAGS_IUSERVER_ACTIVATE_IN_CLIENT_SESSION_ONLY 0x20

Once you make this change then the JIT debugging window is displayed again. I believe that all of this relates to various session 0 security changes made by Microsoft.

Sourced from this post: http://forums.arcgis.com/threads/69842-Debugging-your-SOE-on-Windows-8

Paul
  • 1,502
  • 11
  • 19
blackdemon
  • 131
  • 1
  • 4
  • Answers should be self-contained, so please provide a solution _here_. You still can reference the forum, but it shouldn't be the only thing you give as an answer – stefan May 29 '13 at 10:13
  • Beware of a typo in blackdemon's comment. It should be: reg add “HKCR\AppID\{E62A7A31-6025-408E-87F6-81AEB0DC9347}” /v AppIDFlags /t REG_DWORD /d 8 /f (missing backslash). Took me a while to figure that out ;) – Grzegorz May 05 '16 at 11:31
6

Debugger.Launch would launch an application with a visual GUI. By default services do not interact with a desktop and thus anything they do cannot be "seen".

Support for interacting with the desktop has slowly been removed from Windows services ("Interact with the desktop" option has been removed from some Server versions for example). I would imagine they've continued this trend.

Windows Services by nature are not GUI applications, they can run before and after a user logs into a desktop and thus cannot show a GUI all the time. It's not generally a good idea to depend on an ability to have a GUI in a Service.

If what you want to do is debug a service, I suggest running it as a regular application so that you can do things like Launch and Debug. Shameless plug: you can see Developing Windows Services in Visual Studio for a way to write a service that supports that.

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98
  • I knew Windows 8 is going to pose problems. :P A quick question: how would you go about debugging `OnInstall` code for a Windows Service that has it's own custom installer steps? – MBender Sep 05 '12 at 09:38
  • I would start with changing the External Action in the project Debug settings to use InstallUtil.exe. That will let you install the service in various ways and you can run it with the debugger. – Peter Ritchie Sep 05 '12 at 14:59
0

Is this a Windows Store app or a desktop app?

Try right-clicking on your project (the C# executable project if that's what you have) and selecting "Properties". Then in the left sidebar of options, click "Debug". In the "Start Action" section, check the box for "Do not launch, but debug my code when it starts".

Now you can hit F5 and run Visual Studio with breakpoints in your code, and it will sit and wait for you to fire up the process. Then run your application (outside of Visual Studio), and Visual Studio will attach the debugger.

Do Not Launch option in Properties

Jennifer Marsman - MSFT
  • 5,167
  • 1
  • 25
  • 24
  • it's neither... it's a windows service – iLemming Aug 31 '12 at 20:19
  • it's something to do with Windows 8 itself. They probably have changed something. I've installed SDK with debugging tools, tried to change registry values, all sorts of things - nothing helped. The service still ignores `Debugger.Launch` and fails on `Debugger.Break` even if I put it in a `try..catch` block – iLemming Sep 04 '12 at 14:41