Search code examples
c#debugginghandlerashx

C#: Can't debug ASHX handler


I have an ASP.net C# 4.0 website project. I am calling an ASHX handler using a jQuery AJAX postback. Normally when I debug C#, I use this method Debug > Attach to Process > select w3wp.exe and start debugging.

When I do this with my ASHX handler Visual Studio says "The breakpoint will not be hit. No symbols have been loaded for this document." Sure enough, when I run the AJAX call to the handler, the breakpoint is not hit.

What confuses me is that I can debug C# files otherwise, i.e. the code-behind of an ASPX file.


Solution

  • It turns out that Visual Studio will not actually load symbols for debugging until it actually tries to run the ASHX handler. My problem turned out to be elsewhere - a bug in the jQuery code that called the handler.

    I didn't see this bug at first so assumed the handler was being hit. Once the handler is called, VS will then allow you to debug it. I didn't realise that ASHX handlers behaved this way, I thought they would work just like a regular C# file.