2

I'm using Visual Studio 2017, .NET 4.6.2, C# 6.0 and Newtonsoft.Json 11.0.2.

I tried loading the symbols so I can step through the code, but neither of the following approaches works:

  • I tried adding "https://nuget.smbsrc.net" (with and without a trailing slash) as a symbol server, but VS says it can't find any symbols there.
  • I downloaded the entire Newtonsoft.Json code, built the solution (after having to unload the Newtonsoft.Json.Tests and Newtonsoft.Json.TestConsole projects, because I couldn't get rid of the errors) and tried to direct VS to the .pdb file in ...Newtonsoft.Json-master\Src\Newtonsoft.Json\bin\Debug\net45, but VS wouldn't accept that either.

Can anyone provide a step-by-step tutorial explaining how to integrate the symbols so I can step through the code?

mike
  • 1,627
  • 1
  • 14
  • 37
  • I think you can just add a local path in the "Symbol file (.pdb) locations" section of the options. – ProgrammingLlama Jun 20 '18 at 13:36
  • Thx, but that is just the same as adding the file in the "No Symbols Loaded" window... – mike Jun 20 '18 at 13:43
  • Tried turning "[Just my code](https://stackoverflow.com/questions/32048766/what-is-just-my-code)" off? – ProgrammingLlama Jun 20 '18 at 13:43
  • "Just my code" is already disabled... – mike Jun 20 '18 at 13:47
  • @mike, Could you load the symbols in your side now? – Jack Zhai Jun 25 '18 at 09:39
  • @Jack Zhai-MSFT: thanks for asking; no, i only needed the symbols for one debugging session so i simply replaced the nuget references to the downloaded project source. if i find the spare time (har,har) or need the sources for other reasons i'll get back to this post and let you know how things worked out. – mike Jun 26 '18 at 21:27
  • @mike, So you have found a better workaround, am I right? If it has been resolved, you could share your solution as an answer, and then mark it. So it could help other community members. Of course, if you get any VS debugger issue, feel fee to post it here. – Jack Zhai Jun 27 '18 at 06:49

3 Answers3

5

I'm using Newtonsoft 11.0.2 but same applies to other versions. The manual method (no source link) is the following:

  1. Go to https://github.com/JamesNK/Newtonsoft.Json/releases. Go to 11.0.2 assets and and download the Json110r2.zip file. Unpack it somewhere.

  2. Put a breakpoint on the newtonsoft method you want to debug.

  3. Run your program, when it stop go to menu: Debug -> Windows -> Modules Find newtonsoft.json.dll. Right click Load Symbols.

  4. It will ask you for the *.pdb file location. Point it to the appropriate one from the Json110r2.zip file (e.g. if you're in a .net framework app 4.5 or higher then it's the one from the ..Json110r2\Bin\net45)

  5. It will now ask you for the *.cs location. Use ...\Json110r2\Source\Src\Newtonsoft.Json

Happy debugging.

Also don't forget to go to Tools -> Options -> Debugging -> General and tick the box "Suppress JIT optimization on module load (managed only). This will help make your debugging experience more sane. Published code like Newtonsoft is built using a release config with optimizations and debugging it like that is hard (non-linear jumps in code, variables that you can't inspect, etc).

Liviu Trifoi
  • 2,980
  • 1
  • 21
  • 28
2

Add the path to the Symbol Source service http://srv.symbolsource.org/pdb/Public to the list of debugger symbol sources in Visual Studio.

From http://www.symbolsource.org/Public/Home/VisualStudio:

  1. Go to Tools -> Options -> Debugger -> General.
  2. Uncheck “Enable Just My Code (Managed only)”.
  3. Uncheck “Enable .NET Framework source stepping”. Yes, it is misleading, but if you don't, then Visual Studio will ignore your custom server order (see further on).
  4. Check “Enable source server support”.
  5. Uncheck “Require source files to exactly match the original version”
  6. Go to Tools -> Options -> Debugger -> Symbols.
  7. Select a folder for the local symbol/source cache.
  8. Add symbol servers under “Symbol file (.pdb) locations”. Pay attention to the correct order, because some servers may contain symbols for the same binaries: with or without sources. We recommend the following setup:
NineBerry
  • 26,306
  • 3
  • 62
  • 93
  • 1
    Microsoft [says](https://learn.microsoft.com/en-us/visualstudio/debugger/specify-symbol-dot-pdb-and-source-files-in-the-visual-studio-debugger?view=vs-2019) `If you use a symbol server other than the public Microsoft Symbol Servers, make sure that the symbol server and its path are trustworthy. Because symbol files can contain arbitrary executable code, you can be exposed to security threats.` That seems like quite a risk to me with an untrusted symbol server anyone can push to? Presumably all I'd need to do is get you to do is open a project that references a DLL I control? – Basic Oct 07 '20 at 19:05
0

As of this writing, the current, stable release of Newtonsoft.Json is 11.0.2 (https://www.nuget.org/packages/Newtonsoft.Json). It appears 11.0.3 will ship with SourceLink support. i.e. no need to use the SymbolSource service for this library.

https://github.com/JamesNK/Newtonsoft.Json/issues/1666 http://blog.ctaggart.com/2018/06/newtonsoftjson-enabling-source-link.html

To enable SourceLink in Visual Studio 2017: http://blog.ctaggart.com/2017/03/enable-source-link-support-announcing.html

J. Andrew Laughlin
  • 1,926
  • 3
  • 21
  • 33