62

Is there a way to debug into a decompiled dll using Resharper and if so how do you do this?

For example I am trying to debug into System.Web.Http.ApiController where I have decompiled and can see the source.

I have set a breakpoint but when I run the application it does not break into decompiled breakpoint when debugging.

shA.t
  • 16,580
  • 5
  • 54
  • 111
Noel
  • 5,037
  • 9
  • 46
  • 69

7 Answers7

60

Yes, you can with Resharper 9.0

(not sure for previous versions).

Go to menu "Resharper" > "Windows" > "Assembly Explorer"

  • Add an assembly there with the first button on the left (with a + on it)
  • Then right click on it and choose "Generate Pdb..." (wait until it's done)
  • now you're able to break in the code.

Note however as Jens told, it will probably break license terms

Community
  • 1
  • 1
Fab
  • 14,327
  • 5
  • 49
  • 68
  • 6
    I wrote a blog post explaining how to this in more detail: http://blog.pglazkov.com/2016/02/how-to-debug-any-library-source-code.html – Pavlo Glazkov Feb 27 '16 at 12:00
  • 4
    If you are already debugging go to "Debug" > "Windows" > "Modules". Select the assembly you want to debug and load the "pdb" generated previously by Resharper. – polkduran Aug 05 '16 at 14:47
  • 1
    To use this tip you have to select _Show External Code_ in the context menu of the stack frame in _Call Stack_ window in Visual Studio. – rgb Sep 19 '17 at 14:36
  • 1
    If you are trying to set a breakpoint in the decompiled source code and you get the following warning: _A breakpoint could not be inserted at this location._ put the mouse cursor on a function name and then press _F9_. – rgb Sep 19 '17 at 15:18
  • 1
    @rgb I had problems with breakpoints, but they disappeared after ticking "Suppress JIT optimization on module load (Managed only)" in Options->Debugging->General, as recommended in https://stackoverflow.com/a/32213614/342838 – SlimShaggy Oct 17 '17 at 14:32
16

Debugging facilities are introduced in dotPeek 1.2 and here is a nice post describing how to configure symbol server and dotPeek 1.2 to debug decompiled code from VisualStudio: http://blog.jetbrains.com/dotnet/2014/04/09/introducing-dotpeek-1-2-early-access-program.

Adrian Grigore
  • 33,034
  • 36
  • 130
  • 210
Shkredov S.
  • 2,097
  • 16
  • 8
12

Select an assembly in the Assembly Explorer Window and click Export to Project on the toolbar, or choose Export to Project in the context menu.

More info here

Also, check you have this configuration on the main Debugging options page (Tools -> Options -> Debugging -> General):

Uncheck the "Enable Just My Code" option

Uncheck the "Enable .NET Framework source stepping" option

Check the "Enable source server support" option

Uncheck the "Require source files to exactly match the original version

Tomás Escamez
  • 542
  • 1
  • 6
  • 17
10

No, that will not be possible with just Visual Studio and ReSharper, but there is another product that may help you, .NET Reflector.

The VSPro edition has a "Debug assemblies using the Visual Studio debugger, even if you don’t have the source" feature, which allows you to produce .pdb files and decompiled source code for already built .NET assemblies.

From experience, it had some problems with some assemblies, but I can't remember why that was, so it may or may not help you.

With ReSharper you can look at decompiled source code from the assemblies, in pretty much the same way Reflector will produce decompiled source, but you cannot debug the code with those source files with ReSharper.

Lasse V. Karlsen
  • 380,855
  • 102
  • 628
  • 825
8

As far as i am aware it is not possible to debug the decompiled .net source code using Resharper (up to v6.1)

However, this article explains how you can debug into the .net source with Visual Studio 2010 - if you need instructions for another version of VS, just use the "Other versions" link at the top of the page.

Robbie
  • 18,750
  • 4
  • 41
  • 45
  • 2
    You can decompile the DLLs using dotPeek and then setup a symbol server in VS. See this article https://medium.com/@jackspektor/not-just-my-code-how-to-debug-third-party-libraries-without-decompiling-them-8e47e706dbe7 – Jack Spektor May 09 '17 at 21:55
6

[Full disclosure - I am a Telerik Employee] With the latest release of Telerik's JustCode, you can now debug decompiled code without ever leaving Visual Studio. For more information, you can read my blog post announcing the feature here.

Skimedic
  • 778
  • 7
  • 9
1

You would need to have the corresponding *.pdb files to step into the code.

Otherwise, it might help to decompile the binary file with e.g. Telerik's freely available JustDecompile.

But you should be aware that this might violate license agreements of the third party provider.

Jens H
  • 4,590
  • 2
  • 25
  • 35