28

I have embedded the C# source code into a portable PDB file using the <EmbedAllSources> element in the csproj file, and I have embedded the pdb into the assembly using the <DebugType>embedded<DebugType> as described in Embedding C# sources in PDB with new csproj

My assembly looks like this:

<PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>    
    <EmbedAllSources>true</EmbedAllSources>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>embedded</DebugType>   
</PropertyGroup>

I can confirm that the pdb is type portable, and contains my source code:

enter image description here

According to the release notes for Visual Studio 15.5 the debugger should be able to use these files during debugging:

https://learn.microsoft.com/en-us/visualstudio/releasenotes/vs2017-relnotes-v15.5#EmbeddedSource

I'm using Visual Studio 2017 (version number 15.8.8)

However, when I F11 into the code from my assembly it asks for the sourcecode:

enter image description here

Whilst googling around there's a comment from ctaggart in the discussion https://github.com/ctaggart/SourceLink/issues/192 which says running sourcelink print-urls will print "embed" but mine doesn't, perhaps this is a hint:

enter image description here

Has anyone got this to work successfully? If so can you tell what I'm doing wrong?

Daniel James Bryars
  • 4,429
  • 3
  • 39
  • 57
  • 1
    I'm not an expert, but perhaps this is useful? https://blogs.msdn.microsoft.com/jimgries/2007/07/06/why-does-visual-studio-require-debugger-symbol-files-to-exactly-match-the-binary-files-that-they-were-built-with/ – Olaf Nov 09 '18 at 10:26
  • 3
    It is a "it doesn't work question". Plowing through the "not yet implemented in VS" articles is doggone painful, they are working past each other badly as of late. But it should have all been sorted out in 15.8.8. Just make sure you are using the latest debugging engine: Tools > Options > Debugging > General, "Use Managed Compatibility Mode" should be unchecked. Beyond that a disk reformat or VS reinstall gets attractive. – Hans Passant Nov 10 '18 at 22:54
  • 1
    Can we have a look at your Symbols PDB paths (Tools menu > Options > Debugging > Symbols) and can you show us a screenshot of the Modules (Debug Menu > Windows > Modules) highlighting the row where your PDB is loaded? – Jeremy Thompson Nov 12 '18 at 03:32
  • I'll try a different machine/fresh install/VM etc etc and report back. Has anyone actually had this working? – Daniel James Bryars Nov 15 '18 at 12:58
  • 1
    @HansPassant you were right. I'm not sure what the minimum I needed to do, but I bought a new SSD installed Windows 10 and VS 2017 and it works!!!! If you post this as the answer I'll accept it, bounty is open for another 3 hours. – Daniel James Bryars Nov 16 '18 at 06:15
  • Did you set [`Enable source link support`](https://github.com/ctaggart/SourceLink)? – Dmitry Pavlov May 07 '19 at 11:28
  • This is already answered here https://stackoverflow.com/questions/7311537/how-do-i-embed-source-into-pdb-and-have-debuggers-use-it – divyang4481 Jan 08 '20 at 05:31
  • as well as here https://stackoverflow.com/questions/42714352/embedding-c-sharp-sources-in-pdb-with-new-csproj – divyang4481 Jan 16 '20 at 18:06
  • @divyang4481 No, the 2 linked questions don't have answers for this question. The first link doesn't have a real answer, even though the question is very similar to this one. The second link is asking how to embed the PDB/sources into a nuget package, but not actually providing info on how to get VS to debug such a package. – user9057586 Jul 15 '22 at 20:46

1 Answers1

2

Easiest way is to go to:

Debug -> Windows -> Modules

Inside this list, you should be able to find your assembly (dll/exe).

Right click it -> Load Symbols

It will ask for where to load the symbols from.

Navigate to the directory where your matching .pdb file is.

It should auto load. Stepping into, or having uncaught errors in this referenced assembly should trigger a break in that code, or ask you to navigate to the code file that corresponds to the file that threw the error.

In our process, we generally have to navigate to the nuget cache to find the pdbs for our installed nuget packages. (%UserProfile%/nuget/packages/YourPackage/VersionNumber/../..)

We also package up the source with those packages and navigate to those /nuget/packages .cs files as well, though, any corresponding .cs file should allow it to load.

sayah imad
  • 1,507
  • 3
  • 16
  • 24
KrisSodroski
  • 2,796
  • 3
  • 24
  • 39
  • 2
    There is not a PDB file. The OP is using the Embedded option for the PDB, so its actually in the exe or dll. – StingyJack Feb 27 '21 at 05:13