Welcome to MSDN Blogs Sign in | Join | Help

Debugging a Partial Trust ClickOnce Application

Although the theory is that by the time we deploy a finished application it's already fully debugged we all know that in practice things rarely go that smoothly.  So what happens if you deploy a partial trust ClickOnce application that starts to crash when it's run?  Well, if you're lucky enough to have the problematic application stay alive for as long as it takes you to attach a debugger you're golden.

However if the crash occurs somewhere along the startup path, or if the debugger shows that something went wrong and got you into a bad state before you could attach it you might want to have the debugger run before the process even starts.

That's where things start to get tricky -- since ClickOnce is responsible for starting up your application, you can't just tell it to run the debugger for you.  Instead, you can use the gflags tool from the Debugging Tools for Windows to intercept the start of your process.  For a partial trust application, AppLaunch will be the real entry point, so you'll want to launch your debugger when AppLaunch starts.

In the gflags Image File section, set AppLaunch.exe as the image, check the debugger box, and put the full path to your debugger in the debugger field.  I tend to use either Mdbg or WinDbg for this, depending on what kind of error I'm debugging.

Setting up a debugger for AppLaunch

Once you've got that setup you can launch your ClickOnce application normally and the debugger will start ready to run the application.  If your app no longer starts up, make sure that the full path to the debugger is correct, since if Windows fails to find it, it will fail the CreateProcess for AppLaunch as well.

Finally, when you've solved the problem, you'll probably want to go back to gflags and uncheck the debugger box so that your partial trust applications no longer run under the debugger.

A couple of quick notes on this -- since all partial trust code runs through the same AppLaunch entry point, setting this up will cause all partial trust ClickOnce apps to run under the debugger, not just the one you're debugging.  The same technique can be used for a FullTrust ClickOnce application as well; in that case you'd use the name of your application's .exe file instead of AppLaunch.

Published Tuesday, March 28, 2006 10:05 AM by shawnfa
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Debugging Partially Trrusted ClickOnce Apps

Tuesday, March 28, 2006 2:48 PM by Windows Forms Documentation Updates
Shawn over at the .NET Security Blog has a great tip about using gflags to debug a ClickOnce app that...

# MSDN Flash Resources - 13 Apr 06

Thursday, April 13, 2006 8:08 AM by Robert Burke's Weblog












Web Resources



 

[Default] April MSDN Magazine
Get a handle on...

# HOW TO: Debugging ClickOnce Applications

Monday, May 15, 2006 12:19 PM by Neno Loje's Treasury

Debugging ClickOnce Applications that Use System.Deployment.Application
Debugging a Partial Trust...

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker