If you are an application developer on Windows Media Center you've probably experienced some pain with our Details view of the stack trace, mostly because you can't copy + paste nor see the entire stack traces if it is over a certain length. Starting in Windows 7 you can now launch Event Viewer and navigate to the Applications and Services Logs > Media Center node to see these stack traces. For example, the screenshot below is what you would see if you ran the MarkupDebugging.mcml sample within Windows Media Center and pressed the button labeled 'Crash The Application'. Note this is independent of the EnableErrorDetails registry key enabling the 'Details' button on the dialog end users see when an application crashes -- this event will always be written. This log file is one of those gathered with the Media Center Diagnostic Tools I posted about here making it really helpful to communicate your applications crashes to us during the beta.



Categories: Tools | Windows Media Center | Debugging | Comments [0] | # | Posted on Saturday, January 17, 2009 12:44:23 AM (GMT Standard Time, UTC+00:00)   

I have been working on some debugging topics that will hopefully eventually be included in the Windows Media Center SDK for Windows Vista, and I wanted to put some of these topics together and create an end-to-end scenario demonstrating how you can use Visual Studio 2005 to debug your Windows Media Center application code as it is running within Windows Media Center.

Please note that these instructions require Visual Studio 2005 Professional Edition or higher because the lower editions of Visual Studio 2005 (such as the Express Editions) do not include a debugger that allows you to attach to running processes.

As I wrote this blog post, I tried out these steps with the Q podcast and video blog client sample application that is included in the Windows Media Center SDK.  However, the same set of steps can be used for any Windows Media Center application that includes an add-in assembly.

Step 1 - Build and install the Windows Media Center application

The first step to start debugging your application is to compile your code in Visual Studio 2005, install the resultant assembly to the GAC, and use RegisterMceApp.exe or RegisterApplication to register the application so that it can be launched from within Windows Media Center.

Step 2 - Enable Windows Media Center add-in launch debugging

Set the following registry value on your system to cause a Windows Media Center dialog to appear when attempting to launch any add-in. The dialog will display the process name and process ID that you can use to attach a debugger, set breakpoints, and step through the code in your add-in 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)

Step 3 - Launch Windows Media Center and click on the entry point to start your add-in

After setting the EnableAddInLaunchDebugging registry value, launch Windows Media Center and click on the entry point for your application.  When doing this, a dialog box like the following will appear and you can use it to attach a debugger:

Windows Media Center add-in debugger attach prompt

Step 4 - Attach to the ehexthost process in Visual Studio 2005

After launching your application in Windows Media Cener, leave the Debug Application dialog open and launch Visual Studio 2005 Professional or higher.  Click on the Tools menu and choose Attach to Process...  A dialog like the following will appear:

This dialog lists all running processes on your system.  Locate the process name and process ID that is listed in the Debug Application dialog in Windows Media Center, click on it to highlight it and then click the Attach button to cause the Visual Studio debugger to attach to the process.

Note that if Visual Studio 2005 was already running when you clicked on your Windows Media Center application, you may need to click the Refresh button in the Attach to Process dialog before the process you are looking for appears in the list.

Step 5 - Configure symbol settings for the add-in assembly in Visual Studio 2005

Now that you have attached to the process, you need to configure symbol settings so that you can set breakpoints and debug your add-in assembly code.  Open the Modules window in Visual Studio by pressing Ctrl + Alt + U or by going to the Debug menu, choosing Windows and then choosing Modules.

When the Modules window appears, locate the DLL that represents your add-in assembly, right-click on it and choose Symbol Settings...  A dialog like the following will appear:

Use the new folder icon to add a symbol file (.pdb) location.  Provide the full path to the \bin\<flavor> directory for the built binary for your add-in assembly.  Make sure to choose the correct <flavor> (either debug or release) depending on which flavor of the add-in assembly is currently running in Windows Media Center.  After adding the symbol file location, make sure that the check box next to the symbol path is checked and then click OK to dismiss the symbol settings Options dialog.

You can verify that you chose the correct symbol location by looking in the Module window and verifying that the Symbol Status for your add-in assembly now says Symbols Loaded.

Step 6 - Configure Visual Studio option to allow setting breakpoints in managed code

Go to the Tools menu in Visual Studio 2005 and choose Options...  Expand the Debugging item in the options tree and select General.  Verify that the option named Enable Just My Code (Managed only) is checked.  Click OK to dismiss the options dialog.

Step 7 - Set breakpoints and start debugging

Now you are ready to set some breakpoints in your source code and start debugging.  Open up your source code files in the Visual Studio IDE and click on the line numbers you are interested in debugging to set breakpoints.  After you have set all of the breakpoints you want, click OK on the Debug Application dialog in Windows Media Center to resume execution of your application.  You should see breakpoints hit if you set them in the correct places, and you can use the Visual Studio debugger to step through your code.

Step 8 - Repeat as necessary

If you need to start a new debugging session, you can start again at step 3 of the above instructions.  The process ID in the Debug Application dialog will change each time you launch your application, so you will need to make sure to attach to the new instance of ehexthost.exe in Visual Studio 2005.

Hopefully these steps will be useful to you as you develop your Windows Media Center applications in Windows Vista.

Aaron

 



Categories: Debugging | Comments [1] | # | Posted on Saturday, August 5, 2006 10:13:47 PM (GMT Daylight Time, UTC+01:00)   
RSS
RSS 2.0
Search
Sign In | All Content © 2014 Charlie Owen

This is a personal weblog. The opinions expressed here represent my own and not those of my employer.


Powered by newtelligence dasBlog 2.3.9074.18820