How to get Visual Studio to step into third party assemblies - visual-studio

When I'm debugging or even coding, it would be really uesful to examine third party assemblies but I can only see their metadata.
Given that tools like reflector can decompile assemblies, is there someway or some tool which would allow visual studio to do the same thing?
If I happen to have access to the PDB files for an assemblies, would placing them into my applications bin folder allow me to examine the assemblies content through visual studio?

If you have PDB's for a DLL you can certainly examine the DLL while debugging. Make sure that you have "Just My Code Disabled" and you should be good to go
Tools -> Options -> Debugging -> Uncheck "Just my Code"
There is one caveat though, the Visual Studio debugger will not decompile the assembly. It will read source file information from the PDB, if available, and suggest a location to look for the source file. If you do not have access to the source fie you will be forced to look at the machine disassembly (not decompiled IL) while debugging.

You can load the pdbs through the call stack.
Just right click on a function that you want to load the pdb for, then go to 'Load Symbols'. Browse for the correct pdb, and press OK. After that, it should be able to provide information for the calls in that pdb.

Try .NET reflector Pro here.
I believe it's also available in their free version.

Related

Vs2017 Source Not Available

I´m trying to debug a System.Net.Http.Formating.dll, by clicking at the stack trace:
System.Net.Http.Formatting.dll!System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStreamAsync.AnonymousMethod__c()
I´ve the "Just my code disabled" and I have the following symbols servers:
https://nuget.smbsrc.net
http://localhost:33417/ (dot peek)
Microsoft Symbol Server
I do have the pdb available, however I get the following error/image.
How to properly overcome it?
Why is it such a hassle to debug third party source code at Visual Studio?
After following the link pointed by #Jack Zhai-MSFT I was finally able to understaand the reasons why the .net framework couldn´t be debugged.
It turned out that the symbols were being downloaded without their respective source, because I was pointing to Microsoft Symbol Server instead of http://referencesource.microsoft.com/symbols
Then, my following attempt was to uncheck the "Microsoft Symbols Server" or to change the order at the Symbols menu. To my surprise, I couldn´t delete it, nor change the order, and, even after it was disabled the symbols were still fetched from there.
Perhaps this is a VS2017 community bug.
What I did next, that actually solved it:
Deleted my symbol cache that had misleading pdbs without source
Enabled just my code flag, disabling “Enable .NET Framework source stepping” and started the app, on debug mode
Paused at a breakpoint in which, at the stack, I had access to the code I wanted to debug
Double clicked such stack, and then hit Load Symbols.
This time around, for some reason, the Microsoft Symbol Server was skipped, and the right pdbs were downloaded
Note that, still, I couldn´t download some "optimized symbols" like system.net.http, but I´ll try to figure that out next
Also, I setup the symbols servers using that as a reference, which helped me to promptly get any third party symbols (Except .net)
https://www.symbolsource.org/Public/Wiki/Using
EDIT:
With the help of dotPeeker I was able to get all the missing pdb files by:
Loading these dlls into dotpeeker (ex: System.Net.Http)
Load one of the source files from that DLL
Hit Generate PDB and store it into the same cache folder as VS2017 uses
PHEW!! What a hassle for something that should have been trivial!
To debug third party source code, you could use the .NET Reflector or dotPeek with VS.
Reference:
Is it possible to actually debug 3rd party code using the source decompiled with dotPeek?
Update:
If you just want to debug the .NET source code, see: How do I debug .NET 4.6 framework source code in Visual Studio 2017?

Does nuget package contain pdb symbols

I've included a NuGet package (Edge.js) that I would like to debug by stepping into the source code. When I "step in" it "steps over". I'm guessing this is because there are no symbol file to step in to. Possibly the EdgeJS package was published without sources and this could be the reason. However I don't know how to verify if a NuGet package contains the pdb symbols.
It might also be that I failed configuration of Visual Studio but because I don't know if the NuGet package contains symbols I don't know which way to look.
Thanks for any help
Nuget supports creating packages that contain PDB and source files with the nuget pack -Symbols command. Usually, these packages are uploaded to symbolsource.org for open source projects. Visual Studio can be configured to use symbolsource.org during debugging, see this guide.
However, not every open source project uploads symbol packages to symbolsource.org, so you have to check whether Edge.js does (I don't know that library).
If Edge.js does not provide symbol packages, your options are as follows:
Download the edge.js sources and build locally with debug symbols. Copy the DLL and the PDB to the output folder of your application and start debugging.
Use a decompiler. You don't get as much information as with the debug symbols and source files, but it may suffice for your case. The decompiler that ships with Resharper (commercial tool) is pretty useful for debugging DLLs in this manner.
You can't "step-into" anything if you don't have the source code. Debug symbols won't help in this case.
You can step-into the decompiled code only by using third-party tools like RedGate's Reflector or Telerik's JustCode that decompile the IL on the fly and generate C# code for viewing purposes. These tools don't need the debug symbols to work, although they can use them to make the decompiled code more presentable.

Visual Studio 2010 Runtime Libraries

I wrote a tool that many users would use on their computers. I noticed however, that users who do not have visual studio installed, cannot open my executable. The error says that msvcp100.dll is missing. I found in internet a redistributable package from microsoft, that should apparently provide these dlls. My question is: is there another way to bypass this problem? Something like an option in the project properties?
Yes, you can change a compiler setting to link the C++ standard library classes into your program instead of having a dependency on the DLL. Right-click your project in the Solution Explorer window, Properties. Switch to the Release configuration (upper left). C/C++, Code Generation, Runtime Library setting. Select /MT.
Only do this when you only have a single monolithic EXE. When you use your own DLLs then you really need msvcr100.dll and msvcp100.dll so that the runtime library gets shared between all modules.
It is part of C++ runtime and the target machine needs it. THere are couple of ways to address it.
Please check following link from Microsoft MCVCP100.DLL

Visual Studio, library source when debugging

Just maybe trivial, maybe stupid question.
I have two solutions:
1) The main app
2) The sets of libraries
The first solution is accessible via the SourceSafe with the dll files(from the 2 solution) placed in its lib directory.
In order to debug the main app with the ability to jump to the source code of the libraries from the 2 solution Do i have to add the projects from 2 to 1? And Is it the only one option?
Even if I added (if it is possible to add with omitting certain projects in the SC) projects from 2 to 1 solution, I would have to change dll references in the app which is controlled via SourceSafe and I would mess it up for my colleagues.
What Can I do?
To debug all you need is that all third-party dlls have their corresponding pdb in the same directory. When you step into a third-party function for which you have pdb, Visual Studio will prompt you for the source, At this time you may browse to a local or network share where you have a the third-party source.
The place I used to work for used .NET Reflector to step through external DLLs. It's a Visual Studio add-on that uses reflection to allow you to debug through the source code of .NET binaries (actually their MSIL reversed equivalents) and is pretty simple and efficient when it comes to non-obfuscated code.

Use the official binaries of a library without losing the option to load the source on demand

Within a Visual Studio (2005/2008) Project I'd like to use an open source library. I'd like to link to the binaries so that I'm not responsible for a proper build and can check those binaries into the source control server (SVN).
So far so good, but if I'd like to debug into the open source library or want to take a look at a class implementation I would be forced to add the the source of the project into my solution and than link my project to the source instead of the binaries.
Is it possible to tell Visual Studio a location of the source of a linked binary library so that things like "go to definition" and debug is working?
Absolutely, if you have the pdb symbols its all done for you - look at MFC for example, you get the binaries yet can debug through the source.
If you don't have the symbols, then its a lot more complicated, when you debug through the code it may ask you to show it the source lines, and you'll just have to find them for it (usually the path is the same so its easy).
There are multiple ways you can achieve this.
Like gbjbaanb suggested you can use pdb symbols. It's going to work for both managed an unmanaged code.
If you're using .NET you can debug with Reflector. Oran Dennison wrote how to debug with Reflector and Visual Studio. One of my favorite tools is TestDriven.NET. Author of this tool, Jamie Cansale, also blogged about how to debug with Reflector when you have TestDriven.NET. In his article, Jamie has a link to screencast where he demonstrates how to do it step by step.
Last, if you use for your SVN client like TortoiseSVN, you can add files/directories from check in. More details how to Ignore Files and Directories with TortoiseSVN.

Resources