Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Attaching a Debugger to a Windows Media Center Application using Visual Studio

You can use Visual Studio to debug Windows Media Center application code. Visual Studio 2008 Professional Edition or higher is required because other editions of Visual Studio 2008 (such as the Express Editions) do not include a debugger that allows you to attach to running processes.

Note    Only Windows Media Center applications that are implemented as .NET assemblies can use this feature.

  1. Enable Windows Media Center to allow you to attach a debugger to your application process.

    Windows Media Center can display a dialog box that displays your process ID when you run an application. Then, you can use Visual Studio to attach a debugger to the application process. To enable this feature, set the following registry key:

    Path: HKCU\Software\Microsoft\Windows\CurrentVersion\Media Center\Settings\Extensibility

    Key: EnableAddinLaunchDebugging

    Data type: REG_DWORD

    Value: 1

  2. Build and install the Windows Media Center application.
    • Compile your code in Visual Studio 2008.
    • Install the resulting assembly to the Global Assembly Cache (GAC).
    • Register the application so that it can be launched from within Windows Media Center. You can use RegisterMceApp.exe or the ApplicationContext.RegisterApplication method.
  3. Enable Windows Media Center to launch application debugging.

    Set the EnableAddInLaunchDebugging registry value on your computer, which displays a Windows Media Center dialog box when attempting to launch any application. The dialog box displays the process name and process ID that you can use to attach a debugger, set breakpoints, and step through the code in your application that is executed when Windows Media Center attempts to load and run it.

    [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\Settings\Extensibility]
    EnableAddInLaunchDebugging = 1 (REG_DWORD)
    
    
  4. Launch Windows Media Center and start your application.
    • Launch Windows Media Center and click on the entry point for your application. A dialog box is displayed, which you can use to attach a debugger.

    The Debug Application dialog box

  5. Attach to the ehexthost process in Visual Studio.
    • Navigate away from the Debug Application dialog box without closing it, and then start Visual Studio. From the Tools menu, choose Attach to Process. A dialog box is displayed that lists all running processes on your system.

      The Attach to Process dialog box

    • Locate the process name and process ID that were listed in the Debug Application dialog box in Windows Media Center. Select it, and then click the Attach button.

      Note   If Visual Studio was already running when you started your Windows Media Center application, you might need to click the Refresh button in the Attach to Process dialog box so that your application process is listed.

  6. Configure symbol settings for the application assembly in Visual Studio.

    You must configure symbol settings so that you can set breakpoints and debug your application assembly code.

    • In Visual Studio, from the Debug menu, choose Windows, and then choose Modules.
    • In the Modules window, locate the DLL that represents your application assembly, right-click it, and choose Symbol Settings.

      The Options dialog box

    • In the Options dialog box, click the New Folder icon to add a symbol file (.pdb) location. Provide the full path to the \bin\<debug or release> directory for the built binary for your application assembly. Make sure that the check box next to the symbol path is selected, and then click OK.

    You can verify that you chose the correct symbol location: in the Module window, verify that the Symbol Status for your application assembly says Symbols Loaded.

  7. Configure Visual Studio to allow setting breakpoints in managed code.
    • In Visual Studio, on the Tools menu, choose Options.
    • In the left pane, expand Debugging, and then select General
    • Verify that Enable Just My Code (Managed only) is checked. 
    • Click OK.
  8. Set breakpoints and start debugging.
    • Open your source code files in the Visual Studio IDE and set breakpoints on the lines you want to debug.
    • Navigate back to Windows Media Center and click OK in the Debug Application dialog box to resume execution of your application.

    The application should stop at the breakpoints you set, allowing you to use the Visual Studio debugger to step through your code.

If you need to start a new debugging session, start again at step 4. The process ID in the Debug Application dialog box changes each time you launch your application, so you must attach to the new instance of ehexthost.exe.

See Also

Show: