dotnet / dotnet/docfx

[Bug] Source links for generated PDB documents under obj/ still point to 404

Open
#11,138 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
4.4k
Forks
890
Avg merge
2h 9m
Merged PRs (30d)
11

Description

**Describe the bug**
When generating API documentation from compiled assemblies, source-generated members whose PDB document is under `obj/` can still get a "View Source" link pointing to a non-existent repository file.
This happens on DocFX 2.78.5 even though #10854 added a guard against generating invalid links for files under `obj/`.
In this case, the PDB/source metadata itself is valid and `sourcelink test` passes, but DocFX still emits a GitHub link to the generated `.g.cs` file under `obj/`, which returns 404.
**To Reproduce**
1. Build a project that exposes public members generated by a Roslyn source generator and produces a portable PDB with Source Link enabled.
I reproduced this with NetCord and the generated method:
```c#
NetCord.Rest.MessageProperties.WithContent(string?)
```

2. Generate API documentation from the compiled assembly/PDB with DocFX 2.78.5.
3. Inspect the PDB documents:
`/NetCord/Rest/MessageProperties.cs` has a valid Source Link URL: https://raw.githubusercontent.com/jedrek0429/NetCord/43e938735f37050dcbfbedab5edbf35224d63ac9/NetCord/Rest/MessageProperties.cs, while the generated document `NetCord/obj/Release/net10.0/MethodsForPropertiesGenerator/MethodsForPropertiesGenerator.MethodsForPropertiesGenerator/NetCord.Rest.MessageProperties.g.cs` has no Source Link URL.
4. Verify that the Source Link tests pass.
5. Open the generated documentation for MessageProperties.WithContent.
DocFX generates this “View Source” URL: https://github.com/jedrek0429/NetCord/blob/43e938735f37050dcbfbedab5edbf35224d63ac9/NetCord/obj/Release/net10.0/MethodsForPropertiesGenerator/MethodsForPropertiesGenerator.MethodsForPropertiesGenerator/NetCord.Rest.MessageProperties.g.cs, which returns 404.

**Expected behavior**

DocFX should not generate a repository “View Source” link for a generated PDB document under obj/ when that document has no valid Source Link URL.

For this example:

* MessageProperties.Content should continue linking to the handwritten MessageProperties.cs
* MessageProperties.WithContent should have no source link rather than a broken 404 link

**Context**

* OS: macOS
* Docfx version: 2.78.5
* .NET version: 10

**Additional context**

This appears related to #10854.

The existing /obj/ guard is in GitUtility.TryGetFileDetail, which covers source paths resolved directly from syntax trees.

When documentation is generated from compiled assemblies, VisitorHelper.GetSourceDetail can instead use `SymbolUrlResolver.GetPdbSourceLinkUrl(compilation, symbol)`

That path appears to bypass the existing /obj/ protection.

A possible fix would be to apply the same exclusion when resolving PDB document names in SymbolUrlResolver.SourceLink.cs, although there may be a better way to detect that a PDB document has no repository-backed source.

Contributor guide

Open the contributing guide

Research direction

Start with SymbolUrlResolver.SourceLink.cs and VisitorHelper.GetSourceDetail, then compare their PDB path handling with the /obj/ protection in GitUtility.TryGetFileDetail. Reproduce the NetCord source-generated member case and review the existing Source Link tests. Done means handwritten sources retain valid links while generated PDB documents under obj/ produce no repository View Source link.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.