Quantcast
Channel: Beyond the Box
Viewing all articles
Browse latest Browse all 30

Remote Debugging in ASP.Net with Reflector Pro, Part 2 - Regenerated Assemblies.

$
0
0

In my previous post Remote Debugging in ASP.Net with Reflector Pro, Part 1, I touched on a more complicated potential scenario where the assembly you want to debug does not have a debugger signature. This requires Reflector Pro regenerate the assembly before debugging is possible. And, a further complication occurs if the assembly is also strong name signed. None of this was explored in the previous post, so in this post I intend to show you how to deal with these situations and successfully debug such assemblies.

I should clarify here that this post continues on the specific scenario of remote debugging with an ASP.Net web server. While there are still portions of this post and the previous one relevant for debugging locally, overall debugging locally is far more straightforward.

By the way, if you're interested in a broader look at the overall topic, or just a bit of background to this post, take a look at the companion post Remote Debugging in ASP.Net with Reflector Pro, Part 1

Assembly without Debugger Signature.

"What's a debugger signature?" I hear you ask. The debugger signature in an assembly allows a debugger (e.g. Visual Studio debugger) to identify which pdb file is associated with each assembly.

An assembly can be built by Visual Studio with or without debug info. Setting Debug Info to 'none' results in no pdb file being created and no debugger signature written into the assembly. The Debug Info option in Visual Studio is in Advanced on the Build properties tab.

Strong Name Signed Assembly

If the assembly is also Strong Name signed, there's an additional (but not insurmountable) complication to deal with.

It's important to clarify here that the Strong Name signature is not the same as the Debugger Signature. Strong Name signing is a security mechanism by which the Common Language Runtime can determine if an assembly has been modified since it was built.

Clearly the presence of a Strong Name signature is important when Reflector Pro needs to rebuild the assembly to add a debugger signature. If an invalid Strong Name signature exists on the rebuilt assembly, the runtime will reject the altered dll and the application will fail to run.

Reflector Pro Wants to Rebuild the Assembly

So, here's the situation: You've identified that being able to debug code in a 3rd party dll would be invaluable. After selecting the assembly in Reflector's 'Choose Assemblies to Debug' dialog, you receive a prompt to add a debugger signature and regenerate the assembly.

The example I'm presenting here is based on the release build of the open source log4net.dll assembly.

Setdevpath

Reflector Pro forces you to click 'Set DEVPATH' so go ahead and do this.

The following message from Reflector Pro provides some background to the DEVPATH setting. However, setting DEVPATH on the local machine won't help with remote debugging, but go ahead and click OK anyway because this is the only way to enable the Regenerate button.

Devpath

Now you can click the 'Regenerate' button.

Regenerate


After a few moments, Reflector Pro will have created the new dll and additionally produced a pdb file to enable debugging.

Finished

Note that the next time you open Reflector's 'Choose Assemblies to be Debugged' dialog, it will list 2 items for your chosen assembly, with only the rebuilt assembly being selected.

Select

Remove Strong Name Signature

Remember the secondary issue regarding strong name signed assemblies that I mentioned at the start of this post? Well, if your assembly was Strong Name signed the signature verification will fail with the rebuilt assembly. If you use this assembly in your application as it is, expect an error page like this:

Strong name signature could not be verified

The solution is to simply remove the strong name signature so that we end up with an unsigned assembly. NirSoft has a free command line tool that performs this very task, aptly named SNRemove.

Using the –d switch, you can use SNRemove to display the strong name signature. In the command line output below, you can see the strong name signature for the rebuilt dll (before removing the strong name signature) has been set to all zeros by Reflector Pro.

C:\ProgramData\Red Gate\.NET Reflector\DevPath>snremove.exe -d log4net.dll

Strong name signature in log4net.dll:

00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

The –r switch removes the strong name signature…

C:\ProgramData\Red Gate\.NET Reflector\DevPath>snremove.exe -r log4net.dll

Successfully removed the strong name reference from log4net.dll

Using the –d switch again to confirm the signature has been removed.

C:\ProgramData\Red Gate\.NET Reflector\DevPath>snremove.exe -d log4net.dll

log4net.dll doesn't contain a strong name signature.

Installing the Debug Assembly on the Web Server

Let's not lose sight of our ultimate objective: remote debugging.  There's an additional step we need to take to get there. Reflector Pro has created a new dll to use for debugging, and we've taken steps to ensure it will work, but it's still only on our local PC. We need to copy it to the remote server so that the ASP.Net application uses this alternate dll while we are debugging.

We only need to use the alternate dll temporarily, so keep a copy of the original dll so you can restore it later. In this example, I've added '.ORIGINAL' to the filename of the original file, and then copied in the rebuilt dll.

Original

All Done! (well, almost)

Everything should now be in place for you to attach your debugger remotely and successfully step through the code. I won't go into details here because it's all covered in Remote Debugging in ASP.Net with Reflector Pro, Part 1.


Viewing all articles
Browse latest Browse all 30

Latest Images

Trending Articles



Latest Images