Scenario
Debug an external .dll that contains no SourceLink. There are .dll and .pdb files alongside standalone source .cs files. Can't tell Rider to use exact .cs files for debugging symbols from external .dll.
The .pdb file contains paths to corresponding .cs files. These paths correspond to appropriate .cs files on the machine where the binaries were built. Sample Scenario:
- .pdb file:
C:\Users\Dmitry.Kazantsev\RiderProjects\ExternalLib\ExternalLib\Bin\Debug\net9.0\ExternalLib.pdb; - it contains no SourceLink (see an alternative short explanation below [1]);
- the .pdb file contains a path to a source file, for ex.
C:\Users\Dmitry.Kazantsev\RiderProjects\ExternalLib\ExternalLib\LibClassWorker.cs
When paths to .cs from .pdb is not valid (can't be resolved) on the current machine (either due to rename, nor the binaries were moved from another machine, nor random .cs file placement), Rider can't navigate to a method of such a library and can't Step Into it. Rider suggests decompiling it:
Workaround
There is a feature in ReSharper that allows resolving this problem: Folder Substitutions.
Rider supports this feature but, unfortunately, has no UI for that. There is how it can be done in Rider:
- Get the original path to a desired source file from the .pdb:
- Open the Assembly Explorer in Rider (View | Windows | Assembly Explorer);
- Select Open and choose the .dll (or exe) file of the corresponding .pdb:
- Find the original path to the .cs file (which you need to debug):
- In the example above, the path to the original file is
C:\Users\Dmitry.Kazantsev\RiderProjects\ExternalLib\ExternalLib\LibClassWorker.cs; - Consider you have this
LibClassWorker.cs, but it is in a different directory (because the .dll you reference/debug was built on another machine). For ex, you have this file hereC:\Area\LibClassWorker.cs; - Open one of the layer-based .DotSettings file;
- <SolutionFolder>/{Solution}.DotSettings - Team-Shared;
- <SolutionFolder>/{Solution}.DotSettings.user - Personal;
- This Computer layer. You can find it as below: Help | Diagnostic Tools | Special Files and Folders -> R# global settings -> GlobalSettingsStorage.DotSettings;
- Compose an entry as per below pattern:
- Use these char codes in the path inside of
<s:String {here}></s:String}>Character Unicode code :_003A\_005C._002E(space) _0020 - Sample entry:
<s:String x:Key="/Default/Environment/ExternalSources/PdbNavigation/FolderSubstitutions/=C_003A_005CUsers_005CDmitry_002EKazantsev_005CRiderProjects_005CExternalLib_005CExternalLib/@EntryIndexedValue">C:\Area</s:String> - Where
C_003A_005CUsers_005CDmitry_002EKazantsev_005CRiderProjects_005CExternalLib_005CExternalLibis a path composed from the path to the original file (taken from .pdb). - And
C:\Areais a path to the LibClassWorker.cs where you have it on your machine;
- Use these char codes in the path inside of
- Paste the composed entry in between
<wpf:ResourceDictionary ...></wpf:ResourceDictionary>in the DotSettings file;
- Save the edited file and try to navigate to a corresponding symbol from Rider.
Should you wish a UI for this feature, feel free to upvote this: Folder substitution functionality Folder substitution functionality
[1] Note: a SourceLink is an optional (but widely used) section inside a .pdb file. It contains an URL to symbol server (a repository) where source files that were used to build an application are stored. Having a path to the repository and other meta-data (in .pdb), IDE can download .cs files when it is necessary (when Go To Declaration or Step Into is invoked). Having a copy of a .cs file (alongside .pdb) opened in IDE one can put breakpoints there and debug it step-by-step. Except a SourceLink (which is optional), a .pdb always contains absolute paths to the source files. These paths are being used when the application is being debugged on the same machine where the project is built. It is used in the same way as a SourceLink, except the downloading step. There is no need to download source files when they are right here on the developer’s machine.
Comments
0 comments
Please sign in to leave a comment.