Home > Microsoft .Net Development Tips > Application Testing and Security > Debugging hosted applications with VS.NET
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

APPLICATION TESTING AND SECURITY

Debugging hosted applications with VS.NET


Paul Kimmel
06.01.2004
Rating: -5.00- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


If you're going to build enterprise solutions, some of your assemblies are bound to be hosted by other applications. A huge part of knowing how to code is having good debugging skills, but hosted assemblies can be challenging to debug unless you know that Visual Studio .NET supports debugging hosted applications by attaching to the host directly. This tip from InformIT, explains how to debug hosted applications.


Attaching to the Host Application

Our focus is on testing the serviced component rather than the client application. To accomplish the testing with the client and service in the same assembly, we can set the client as the startup project but start without debugging by selecting Debug, Start Without Debugging. This step will start the client, leaving the debugger available to debug the hosted application.

After the client is running, click the button in the application to create and load an instance of the host process, dllhost.exe. When the host process is running, we can use the available integrated debugger—because we started the client without debugging—and attach the debugger to the host process. To attach to the host process, follow these steps (using the associated figures as a visual guide):

  1. Select Debug, Processes to display the Processes dialog box.
  2. Navigate to the dllhost.exe process, click it, and click the Attach button.
  3. In the list called Choose Program Types That You Want To Debug, check only the Common Language Runtime option, and click OK.
  4. Click the Close button in the Process dialog box. The dllhost.exe host will be shown in the Debugged Processes list in the Processes dialog box.

You may run into a bit of trouble if several instances of your host are running. For example, if an instance of dllhost.exe is running on behalf of some other, non-managed service, you'll get an error indicating that the host needs to be running managed code to debug with the .NET debugger. Additionally, if you select more than the Common Language Runtime option—for example, if you select Native—the debugger takes a lot longer to load.

After you've attached to the host process and have clicked Close, the integrated environment will load the required assemblies and modules needed to debug your hosted application. In our example, these will be the binaries needed to support the LuckyNumberGenerator.

Debugging and Testing Your Hosted Assembly

After the debugger has attached to your assembly's host application, you can debug in .NET as you would debug anything else. You can set breakpoints and watches; examine the stack or memory; view and switch between threads, if applicable; and use the Immediate/Command window to run and explore code while in break mode.

To try out debugging a hosted assembly, set a breakpoint in the GetLuckyNumber method in the service. Switch focus to the client and click the button we placed in the form. If everything is pieced together correctly, the IDE will break at the point you indicated.

At this point, you can perform any of the operations you might normally perform when debugging an executable or DLL that's not hosted by another process.

Finished Debugging?

When you're finished debugging, you can select Debug, Stop Debugging or Debug, Detach All. Selecting Stop Debugging may kill the host process. If you want to continue running the host application, attach to another host, or attach another service to the same host, select Detach All, which will detach the debugger from the host, leaving the host intact.

    TIP
    You also have the option of detaching or terminating the host from the Processes dialog box

You can prevent the IDE from killing the host process by changing the When Debugging Is Stopped option. If you want the host to terminate when debugging stops, select Terminate This Process. If you want the host to remain intact, select Detach from This Process.


Read more about the creating COM+ serviced components in the complete article at InformIT.


Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
.NET Framework security best practices
New features in Windows 7 bring new UI considerations for developers
Podcast: Windows CardSpace authors speak
Book excerpt: Java EE and .NET security interoperability
Book excerpt: Advanced Windows Debugging
Book excerpt: Pragmatic unit testing in C# with NUnit
Security interoperability with .NET/WSE and WebLogic Workshop 8.1
Windows Developments: Product news, December 2007
How to avoid regression bugs while adding new features
VB code: New additions, November 2007
VB code: Application security downloads

Application Testing and Security
Test-driven development in .NET yields complete unit test coverage
How to write installers in Vista that work correctly under UAC
How to elevate programs' privileges correctly using Vista's UAC
Internet Explorer 8 beta's development tools add source visualizations
Microsoft previews new features in Visual Studio 2010
Advanced Windows Debugging Book Chapter and Podcast
Book excerpt: Advanced Windows Debugging
Book excerpt: Pragmatic unit testing in C# with NUnit
Security interoperability with .NET/WSE and WebLogic Workshop 8.1
How to avoid regression bugs while adding new features

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
common test platform  (SearchWinDevelopment.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts