Skip to content

feat(dotnet): disambiguate assemblies that share namespaces (assemblyUidPrefixes) - #2

Closed
MaceWindu wants to merge 10 commits into
mainfrom
fix/8966-uid-prefixes
Closed

MaceWindu wants to merge 10 commits into
mainfrom
fix/8966-uid-prefixes

Conversation

@MaceWindu

@MaceWindu MaceWindu commented Aug 7, 2026 •

Copy link
Copy Markdown
Owner

Draft of a fix for dotnet/docfx#8966, opened against the fork for review before proposing it upstream. Generalizes the custom/linq2db globalPrefix hack into a project-agnostic, tested option, and has been validated against the real linq2db docs build (see Validation below).

Problem

A docfx UID is Roslyn's documentation comment id minus its X: prefix (VisitorHelper.GetId), so it carries no assembly component. When one docfx project documents several assemblies that declare the same namespace, their APIs collapse onto one identity:

  • MergeMembers keys a flat Dictionary<string, MetadataItem> by UID — namespaces and classes are silently merged, everything else is dropped with an Ignore duplicated member warning.
  • The .yml file name is the UID, so pages overwrite each other and .manifest warns.
  • At build time DocumentBuildContext.XRefSpecMap reports DuplicateUids and picks the winner alphabetically by href — which is why every link to a shared namespace lands in one project.

This is common for platform/version specific packages that intentionally expose the same API surface (linq2db's per-EF-Core-version packages, Xamarin/WinForms/WPF variants, Abstractions + implementation pairs).

Related: dotnet#9371, dotnet#2041, discussions dotnet#8204 and dotnet#8018.

Why not resolve hrefs at the metadata stage

On dotnet#8966 the suggestion was to "resolve the right project for the API pages by moving the resolve logic from build stage to metadata stage". That fixes hrefs only. It does not stop MergeMembers from dropping or merging same-UID pages, so the affected APIs still never get a page. Disambiguating the UID itself is the only fix that addresses all four symptoms.

Solution

A project level option plus a narrow per entry escape hatch, both off by default.

assemblyUidPrefixes — a top level docfx.json property

Maps an assembly name to a prefix that is prepended to the UID of every API declared in that assembly:

{
  "assemblyUidPrefixes": { "MyLib": "Core", "MyLib.Ef8": "Ef8" },
  "metadata": [
    { "src": [ "src/MyLib/MyLib.csproj" ],         "dest": "api/core" },
    { "src": [ "src/MyLib.Ef8/MyLib.Ef8.csproj" ], "dest": "api/ef8" }
  ]
}

MyLib.Widget becomes Core.MyLib.Widget and Ef8.MyLib.Widget, so each keeps its own page, TOC entry and cross references. Assemblies that are not listed are untouched, so BCL/NuGet references, Microsoft Learn links and existing xref maps are unaffected.

It sits next to metadata rather than inside an entry because it has to be project wide. An entry mints UIDs not only for the APIs it documents but also for the APIs it references — the Ef8 entry emits reference UIDs for the MyLib types in its own signatures — and those must come out identical to the UIDs the MyLib entry produced. A per entry list cannot do that, because an entry cannot see another entry's settings.

Measured on the linq2db docs build: replacing this with a per entry prefix on all 16 entries leaves 6690 cross-entry references across 163 pages pointing at UIDs no page has. They render as plain text with no link, no warning and no error — the total warning count is identical either way. The practical rule that follows is in the docs: list every assembly whose APIs appear in another assembly's public signatures, not just the ones whose namespaces collide.

uidPrefixOverride — per entry, for entries that build the same assembly name

Version specific packages are often one project built several times, sharing an AssemblyName and differing only by target framework, which a map keyed by assembly name cannot separate:

{
  "assemblyUidPrefixes": { "MyLib": "Core" },
  "metadata": [
    { "src": [ "src/MyLib/MyLib.csproj" ],           "dest": "api/core" },
    { "src": [ "src/MyLib.Ef/MyLib.Ef.Ef8.csproj" ], "dest": "api/ef8", "uidPrefixOverride": "Ef8" },
    { "src": [ "src/MyLib.Ef/MyLib.Ef.Ef9.csproj" ], "dest": "api/ef9", "uidPrefixOverride": "Ef9" }
  ]
}

It wins over assemblyUidPrefixes for its own entry's assemblies.

What it fixes: the collision between the entries that declare it. Each gets its own pages, TOC entries and file names, and everything inside those pages — references, <see cref="..."/> links, member anchors — is consistent with them.

What it does not fix, both following from the fact that it names an entry rather than an assembly:

  • Links from other entries into those assemblies. A fourth entry referencing MyLib.Ef.dll cannot know whether you meant Ef8 or Ef9, so those references lose their links silently. The fix needs no extra option: list the assembly in assemblyUidPrefixes too, naming the version that should be the default link target. The override still wins for the assemblies its own entry documents, so both versions keep their pages while every other entry resolves MyLib.Ef references to the chosen one. The trade-off is that all such links go to that one version — a reference cannot resolve to "whichever version the referencing assembly was built against", because by the time the UID is minted the only thing distinguishing the versions is which entry documented them.
  • Two same-named assemblies inside one entry. Every assembly an entry documents gets the same prefix, so a src glob matching the same assembly built for several target frameworks still collides and still reports Ignore duplicated member. Narrowing the glob is the fix there, not a prefix.
situation option
the assembly has a name of its own assemblyUidPrefixes
the assembly is referenced by other assemblies in the project assemblyUidPrefixes
several entries build the same assembly name uidPrefixOverride on each
... and other entries reference it also list it in assemblyUidPrefixes, naming the default target
one entry matches the same assembly several times narrow the src glob

Alternative considered: one option, two-pass compile

uidPrefixOverride alone would be enough if Exec compiled every entry first, collected assembly → prefix from each entry, and only then generated. Cross-entry references would resolve from that collected table and assemblyUidPrefixes would not be needed.

Not done here: it holds every Roslyn compilation in memory simultaneously (for linq2db, 17 projects across multiple target frameworks), and restructuring the compile pipeline is a much larger change than the bug warrants. Worth revisiting separately.

Implementation

The prefix is inserted in the private VisitorHelper.GetDocumentationCommentId, next to the existing globalNamespaceId insertion. That single hook covers uids, comment ids, overload ids, the references table, spec ids, TOC node ids and output file names. It is skipped for type parameters and for symbols with no containing assembly (cref-resolved symbols hit the latter).

uidPrefixOverride is applied in Build right after Compile, since an entry's assemblies are only known once compiled. It stays constant for the whole entry, so the parallel API page generation can read it safely.

Three consumers do not go through that hook and needed to follow the prefix explicitly. Each of these is a bug the globalPrefix hack still has, and each one shows up in the linq2db output below:

  1. SymbolUrlResolver.GetDocfxUrl built hrefs from the raw Roslyn comment id while deriving file names through VisitorHelper, so references and in-page anchors pointed at pages and bookmarks that do not exist.
  2. crefs. XmlComment turns T:Foo.Bar into a uid by pure text strip with no symbol context, so <see cref="..."/> would produce dangling xrefs. A ResolveUidPrefix callback on XmlCommentParserContext resolves the target through the compilation (DocumentationCommentId.GetFirstSymbolForDeclarationId, the same call AddReference already makes) and is supplied by both the mref and apiPage comment parsers. It is a no-op when neither option is set.
  3. API filters now use a new VisitorHelper.GetRawId, so filterConfig uidRegex rules keep matching the actual API surface and existing filter files keep working when the options are enabled.

Namespace display names include the prefix, otherwise namespaces from different assemblies are indistinguishable in the TOC, breadcrumbs and page titles, and the parent-namespace trimming in ToTocItemViewModel (which compares the display name against the parent uid) silently stops matching. With namespaceLayout: nested the prefix groups that assembly's namespaces under a single root node, which also answers discussion dotnet#8018.

A prefix must start with a letter or underscore and may contain letters, digits, underscores and dots, e.g. Core, MyLib.V2 or net8.0. Segments after the first may start with a digit, unlike a namespace, so target framework style prefixes work. The grammar is deliberately stricter than globalNamespaceId — which is inserted the same way and validates nothing at all — because the UID becomes a file name, an xref key and an HTML anchor, and path or UID metacharacters would corrupt all three. Invalid prefixes, empty assembly names and conflicting mappings are reported as InvalidUidPrefix warnings and skipped.

Behaviour when unset

Off by default and inert: GetUidPrefix returns immediately when neither option is configured, so there is no behaviour change and no measurable cost.

Verified byte-exactly: the snapshot suite was run on a clean main checkout and on this branch, and all 497 generated files are SHA-256 identical. Re-verified after each subsequent commit. No .verified.* file is touched by this PR.

Tests

  • test/Docfx.Dotnet.Tests/UidPrefixUnitTest.cs (new, 15 cases): namespace/type/member/overload uids and comment ids; two assemblies sharing a namespace getting distinct uids; cross-assembly references carrying the target's prefix; unmapped assemblies and framework types untouched; crefs, seealsos, exceptions and Overload: crefs, under both options; generics and type parameters prefixed exactly once; composition with globalNamespaceId; filter rules matching unprefixed uids; the override separating assemblies that share an assembly name, winning over the map, and not leaking to other assemblies; and no prefix at all when neither option is set.
  • test/docfx.Tests/MetadataCommandTest.cs (4 new end-to-end cases over two real projects sharing a namespace): the Ignore duplicated member warning and lost page without the options (locking in the regression), distinct pages/manifest entries/TOC entries with the map, the nested TOC grouping, and two entries separated by the override.
  • Serialization round-trip data covers both options for Newtonsoft ↔ System.Text.Json parity, and both are in schemas/docfx.schema.json (which is additionalProperties: false).

Docs

  • docs/reference/docfx-json-reference.md: a section per option, each stating when to reach for it and its trade-off.
  • docs/docs/dotnet-api-docs.md: new "Assemblies that share namespaces" section with three subsections — how to give each assembly a prefix and why the map is project level; what uidPrefixOverride does and does not fix; and "Nominate a default version for links from elsewhere", the setup for pointing other entries at one of several same-named assemblies, written as a procedure with a table of which prefix is used when generating each thing. Closes with a decision table and the caveat that enabling either option changes UIDs, so <xref> links in markdown, overwrite files and external xref maps need updating by hand.

Validation against the linq2db docs build

Tested on linq2db.docs branch docs/republish-uid-prefixes (linq2db/docs#64) — 17 metadata entries, 2389 generated API files.

This is what surfaced the need for uidPrefixOverride. linq2db ships four Entity Framework Core packages built from one shared props file:

Source/LinqToDB.EntityFrameworkCore/LinqToDB.EntityFrameworkCore.props:4
  <AssemblyName>linq2db.EntityFrameworkCore</AssemblyName>

All four (EF3, EF8, EF9, EF10) therefore produce the same assembly name and need four different prefixes. With only the map they collide on one key, trip the conflict warning, and EF9/EF10 keep colliding with EF8 exactly as before.

Both builds were run from source at Roslyn 5.6.0 for an apples-to-apples comparison. All 2389 generated API file names are identical. The site build differs sharply:

globalPrefix hack this PR
Total warnings 1302 67
InvalidBookmark (dead in-page anchors) 1197 1
Ignore duplicated member 28 0
InvalidAssemblyReference 5 0
Errors 0 0

The three consistency fixes account for the difference:

1. Malformed commentId. The hack prepends the prefix to the whole documentation comment id, so it lands before the kind marker:

# hack
commentId: linq2db.T:LinqToDB.AnalyticFunctions.IAggregateFunction`1
# this PR
commentId: T:linq2db.LinqToDB.AnalyticFunctions.IAggregateFunction`1

2. Dead namespace/type hrefs, from the GetDocfxUrl gap:

# hack:     href: LinqToDB.html          <- no such page
# this PR:  href: linq2db.LinqToDB.html  <- the page that exists

3. 1197 dead in-page anchors. Same root cause — the hack generated member anchors unprefixed (#LinqToDB_Internal_SchemaProvider_DataTypeInfo_CreateFormat) while the target pages contain the prefixed bookmark.

The docs PR also fixes two article xrefs the hack was hiding. It rendered <a class="xref" href="LinqToDB.ProviderName.html"> with no warning, and that file does not exist in _site — they were already silently broken links on the published site. This build reports them as UidNotFound instead, and with the UIDs corrected both now resolve.

Verification performed

  • dotnet build -c Release --warnAsError clean across net8.0/net9.0/net10.0.
  • 187 Docfx.Dotnet.Tests, 118 docfx.Tests, 14 Docfx.Build.ManagedReference.Tests pass.
  • Snapshot outputs byte-identical to a clean main baseline (above).
  • dotnet format --verify-no-changes reports nothing in any file touched here.
  • Synthetic repro mirroring [Bug] Duplicate namespaces  dotnet/docfx#8966: without the options, 5 DuplicateUids/UidNotFound warnings and a dropped page; with them, 0 warnings, both A.Shared.Widget.html and B.Shared.Widget.html generated, and each xref resolving to its own project.
  • Real-world: the linq2db docs build above.

Not included

  • The pre-existing globalNamespaceId inconsistency in GetDocfxUrl is left as is, to keep the "no change when unset" guarantee exact.
  • The Roslyn 5.6.0 bump that linq2db 6.4.0's sources need (it adds IPropertySymbol.ReduceExtensionMember / IMethodSymbol.ReduceExtensionMember to SymbolFormatter.Symbols.cs). Unrelated to this fix and would churn snapshots; dependabot Bump the roslyn group with 8 updates dotnet/docfx#11053 covers the upgrade separately. The linq2db build uses custom/linq2db-uidprefix, which is this branch plus that one commit.
  • The two-pass compile refactor described above.
  • Unioning AssemblyNameList when MergeMembers merges a namespace or class page. It is a real gap — samples/seed's own CatLibrary.Core namespace page reports only CatLibrary although half its types come from CatLibrary.Core — but it changes default output, would require a snapshot update, and both shipped templates render only assemblies.0 so nothing would become visible without a template change too. Belongs in its own PR.
  • No CLI option, consistent with the other map/collection valued metadata settings.

Review notes

  • Validate against the real linq2db docs build — done, and it changed the design (uidPrefixOverride was added).
  • Confirm the option names — assemblyUidPrefixes says what its key is, uidPrefixOverride names its relationship to it rather than being its singular.
  • Make the docs say where the map goes in a project with many entries — it is now a project level property, so there is only one place it can go.
  • Say what uidPrefixOverride does and does not fix.
  • Decide whether the two-option surface is acceptable, or whether the two-pass compile alternative should be pursued instead before this goes upstream.

Fixes dotnet#8966, dotnet#9371.

🤖 Generated with Claude Code

@MaceWindu

Copy link
Copy Markdown
Owner Author

Validated against the real linq2db docs build

Tested on linq2db.docs branch test/uid-prefixes (commit 5df43d8), which replaces the
globalPrefix hack in source/docfx.json with these options. 17 metadata entries, 2389 generated API
files. See UIDPREFIX-EXPERIMENT.md on that branch for the full write-up.

This found a real design gap, fixed in a8be8ca

An assembly-name-keyed map cannot express the most common form of this problem. linq2db ships four
Entity Framework Core packages built from one shared props file:

Source/LinqToDB.EntityFrameworkCore/LinqToDB.EntityFrameworkCore.props:4
  <AssemblyName>linq2db.EntityFrameworkCore</AssemblyName>

All four (EF3, EF8, EF9, EF10) therefore produce the same assembly name and need four
different prefixes. With only uidPrefixes they'd all collide on one key, trip the conflict warning,
and EF9/EF10 would keep colliding with EF8 exactly as before. Any project with per target version
builds has this shape.

So the PR now has two options with distinct jobs, both needed in general:

  • uidPrefix (string, per entry) — how to prefix the APIs this entry documents. Scoped to the
    entry, so it separates assemblies that share an assembly name. This is the option most users need.
  • uidPrefixes (map, combined across entries) — how to address APIs documented by another entry,
    whose uidPrefix is not visible from this one.

uidPrefix wins over uidPrefixes for its own entry's assemblies. It's applied in Build right after
Compile, since an entry's assemblies are only known once compiled, and stays constant for the whole
entry so the parallel API page generation can read it safely.

Result: equivalent metadata, substantially more correct site

Both builds were run from source at Roslyn 5.6.0 for an apples-to-apples comparison. All 2389
generated API file names are identical.
The site build differs sharply:

globalPrefix hack this PR
Total warnings 1302 102
InvalidBookmark (dead in-page anchors) 1197 1
UidNotFound 0 2
Errors 0 0

Three concrete bugs in the hack that this PR's consistency fixes eliminate:

1. Malformed commentId. The hack prepends the prefix to the whole documentation comment id, so the
prefix lands before the kind marker:

# hack
commentId: linq2db.T:LinqToDB.AnalyticFunctions.IAggregateFunction`1
# this PR
commentId: T:linq2db.LinqToDB.AnalyticFunctions.IAggregateFunction`1

2. Dead namespace/type hrefs. This is the SymbolUrlResolver.GetDocfxUrl gap described above — it
builds hrefs from the raw Roslyn comment id, which the hack never prefixes:

# hack:     href: LinqToDB.html          <- no such page
# this PR:  href: linq2db.LinqToDB.html  <- the page that exists

3. 1197 dead in-page anchors. Same root cause. The hack generated member anchors unprefixed
(#LinqToDB_Internal_SchemaProvider_DataTypeInfo_CreateFormat) while the target pages contain the
prefixed bookmark.

The 2 extra UidNotFound are true positives the hack was hiding

source/articles/general/databases.md:7   xref:LinqToDB.ProviderName
source/articles/sql/Bulk-Copy.md:85      xref:LinqToDB.Data.BulkCopyOptions

Both use unprefixed UIDs and should be updated — this is exactly the caveat documented in
dotnet-api-docs.md. The hack did not warn, but it did not work either: it emitted
<a class="xref" href="LinqToDB.ProviderName.html">, and that file does not exist in _site. Those
were already silently broken links on the published site. Reporting them is the better behaviour.

Not caused by either fix

The F# entry globs linq2db/.build/bin/LinqToDB.FSharp/Release/**/linq2db.FSharp.dll, which matches
five target framework folders, so the same assembly is loaded five times into one metadata entry and
every member is reported duplicated. Narrowing that glob removes ~28 warnings from both builds.

Kept out of this PR

Building linq2db 6.4.0's sources needs Roslyn 5.6.0, which adds
IPropertySymbol.ReduceExtensionMember / IMethodSymbol.ReduceExtensionMember to
SymbolFormatter.Symbols.cs. That bump is unrelated to this fix and would churn snapshots, so this PR
stays on Roslyn 5.0.0 (dependabot dotnet#11053 covers the upgrade separately).

Regression checks re-run after the extension

  • dotnet build -c Release --warnAsError clean across net8.0/net9.0/net10.0
  • 186 Docfx.Dotnet.Tests (14 in UidPrefixUnitTest, 3 new for the per entry option), 71
    docfx.Tests metadata/schema/serialization tests
  • All 497 snapshot outputs still byte identical, so "no change when unset" still holds

🤖 Generated with Claude Code

@MaceWindu MaceWindu changed the title feat(dotnet): add uidPrefixes to disambiguate assemblies sharing namespaces feat(dotnet): disambiguate assemblies that share namespaces (uidPrefix/uidPrefixes) Aug 7, 2026
@MaceWindu MaceWindu changed the title feat(dotnet): disambiguate assemblies that share namespaces (uidPrefix/uidPrefixes) feat(dotnet): disambiguate assemblies that share namespaces (assemblyUidPrefixes/uidPrefix) Aug 8, 2026
@MaceWindu MaceWindu changed the title feat(dotnet): disambiguate assemblies that share namespaces (assemblyUidPrefixes/uidPrefix) feat(dotnet): disambiguate assemblies that share namespaces (uidPrefix) Aug 8, 2026
@MaceWindu MaceWindu changed the title feat(dotnet): disambiguate assemblies that share namespaces (uidPrefix) feat(dotnet): disambiguate assemblies that share namespaces (assemblyUidPrefixes) Aug 8, 2026
MaceWindu added a commit to linq2db/docs that referenced this pull request Aug 9, 2026
…x build (#64)

* docs: fix cross reference and duplicate assembly issues, refresh docfx build

Replaces the `globalPrefix` hack in the vendored docfx build with the `uidPrefix`/`uidPrefixes` options
proposed upstream (MaceWindu/docfx#2, for dotnet/docfx#8966), and fixes the
issues that surfaced once docfx started reporting them honestly.

Site build goes from 1302 warnings to 67, with no change in generated page count (2389 API files):

  InvalidBookmark          1197 -> 1   dead in-page anchors
  Ignore duplicated member   28 -> 0   F# assembly loaded once per target framework
  InvalidAssemblyReference    5 -> 0   FSharp.Core not resolvable
  UidNotFound                 0 -> 0   two stale article xrefs, fixed here

The old build emitted a malformed `commentId` (`linq2db.T:LinqToDB...`, prefix before the kind marker),
unprefixed namespace and type hrefs pointing at pages that do not exist, and ~1200 member anchors that
did not match the bookmarks on their own pages.

- source/docfx.json: `globalPrefix` -> `uidPrefix` on the four EntityFrameworkCore entries, which all
  build an assembly named `linq2db.EntityFrameworkCore` and so cannot be told apart by assembly name,
  plus a combined `uidPrefixes` map so references between entries resolve.
- source/docfx.json: the F# entry globbed `Release/**/linq2db.FSharp.dll`, matching all five target
  framework folders, so the same assembly was loaded five times and every member reported duplicated.
  Pinned to netstandard2.0, with `references` pointing at the net462 output, the only one that carries
  FSharp.Core next to the assembly.
- articles: `xref:LinqToDB.ProviderName` and `xref:LinqToDB.Data.BulkCopyOptions` now use the prefixed
  UIDs. These were silently broken before: the old build rendered a link to `LinqToDB.ProviderName.html`,
  which is not a page that exists.
- docfx/: refreshed from custom/linq2db-uidprefix (d89a8f030) and documented in docfx/README.md. The 11
  removed assemblies are transitive dependencies the newer Roslyn no longer ships.

Remaining warnings all originate in the linq2db submodule and cannot be fixed here: 60 MSBuild
duplicate-source-file warnings from the analyzer projects, 5 `InvalidFileLink` and 1 `InvalidBookmark`
from XML documentation comments, and `No .NET API detected for linq2db.Compat`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: rename uidPrefixes to assemblyUidPrefixes, refresh docfx build

Follows the option rename in the upstream PR: `uidPrefix`/`uidPrefixes` read as singular and plural of
one concept while being scoped differently, so the map is now `assemblyUidPrefixes`, which says what its
key is.

- source/docfx.json: `uidPrefixes` -> `assemblyUidPrefixes`, and the comment now leads with the map
  since that is the primary option, with `uidPrefix` as the escape hatch for the four
  EntityFrameworkCore entries that share an assembly name.
- docfx/: rebuilt from custom/linq2db-uidprefix (28070313a), which also picks up a fix for crefs being
  left unprefixed when only `uidPrefix` was set.

Build output is unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages, no duplicate member,
`UidNotFound` or `InvalidAssemblyReference` warnings.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: use the merged uidPrefix option, refresh docfx build

Follows the upstream PR collapsing `assemblyUidPrefixes` and `uidPrefix` into a single `uidPrefix` that
accepts either form, so the value shape says which scope applies:

  "uidPrefix": { "linq2db": "linq2db", ... }        // by assembly name, shared by all entries
  "uidPrefix": "linq2db.EntityFrameworkCore.EF8"    // this entry's own assemblies

Both forms are still used here for the same reasons as before. Confirmed by measurement that the object
form is not redundant: building with a string on every entry instead leaves 6690 cross-entry references
into the core assembly, across 163 pages, pointing at UIDs no page has. They render as plain text with
no link and no warning.

docfx/ rebuilt from custom/linq2db-uidprefix (1d0b2de99).

Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: use assemblyUidPrefixes and uidPrefixOverride

Follows the upstream PR splitting the merged option back into two names, since one name accepting a
string or an object hid that the two forms have different scope.

  "assemblyUidPrefixes": { "linq2db": "linq2db", ... }   // project wide, keyed by assembly name
  "uidPrefixOverride": "linq2db.EntityFrameworkCore.EF8" // this entry's own assemblies

Same behaviour as before, and the config comment now says the map is project wide rather than merely
"declared once here", which is what makes references between entries resolve.

docfx/ rebuilt from custom/linq2db-uidprefix (5534e75af).

Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* docs: move assemblyUidPrefixes to the project level

Follows the upstream PR moving the map out of the metadata entries and up to the top level of
docfx.json, next to `metadata`, where a project level setting belongs:

  {
    "assemblyUidPrefixes": { "linq2db": "linq2db", ... },
    "metadata": [ ... ]
  }

The comment now explains the selection rule rather than just the mechanics: every assembly appearing in
another assembly's public signatures is listed, not only the ones whose namespaces collide, because a
reference that comes out unprefixed loses its link with no warning. It also records why
LinqToDB.Identity is absent, and why `uidPrefixOverride` is safe for the EF Core entries: nothing else
in this project references those packages, so no other entry needs to name one of the four versions.

docfx/ rebuilt from custom/linq2db-uidprefix (91955d98a).

Build output unchanged: 67 warnings, 0 errors, 2389 API files, 2407 HTML pages.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
MaceWindu and others added 9 commits August 13, 2026 18:16
…mespaces

A docfx UID is derived from the fully qualified name of an API alone, so
when one docfx project documents several assemblies that declare the same
namespace their APIs collide: `MergeMembers` drops or silently merges the
duplicates, pages overwrite each other, `DuplicateUids` is reported, and
every link to a shared namespace resolves to whichever assembly won.

`uidPrefixes` maps an assembly name to a prefix that is prepended to the
UID of every API declared in that assembly. The maps of all metadata items
are combined before any of them is processed, so references between
metadata items resolve regardless of the order they are declared in.
Assemblies that are not listed are untouched, and the option is off by
default, so generated output is unchanged unless it is configured.

The prefix is applied in `VisitorHelper.GetDocumentationCommentId`, which
covers uids, comment ids, overload ids, references, TOC nodes and file
names. Three consumers needed to follow it explicitly:

- `SymbolUrlResolver.GetDocfxUrl` builds hrefs from the raw Roslyn comment
  id while deriving file names through `VisitorHelper`.
- crefs are resolved textually by `XmlComment`, with no symbol context, so
  a `ResolveUidPrefix` callback resolves the target through the compilation.
- API filters keep matching the unprefixed API surface via `GetRawId`, so
  existing `filterConfig` files keep working when the option is enabled.

Namespace display names include the prefix so that namespaces coming from
different assemblies are distinguishable in the TOC, breadcrumbs and page
titles, and so nested TOC parent trimming keeps matching.

Fixes dotnet#8966
Fixes dotnet#9371

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Found while validating the fix against the linq2db docs build: an assembly name keyed map cannot
express the most common form of this problem. linq2db ships four Entity Framework Core packages built
from one shared props file, so all four produce an assembly named `linq2db.EntityFrameworkCore` and
need four different prefixes. The same shape appears in any project with per target version builds.

`uidPrefix` is a per metadata entry prefix that applies to the assemblies that entry documents and
takes precedence over `uidPrefixes`. The entry's assemblies are only known after they are compiled, so
it is assigned in `Build` right after `Compile`, and stays constant for the whole entry, which keeps it
safe for the parallel API page generation to read.

The two options have distinct jobs and both are needed in general: `uidPrefix` says how to prefix the
APIs an entry documents, `uidPrefixes` says how to address APIs documented by another entry, whose
`uidPrefix` is not visible from this one.

Snapshot output remains byte identical when neither option is set.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ify the two options

Review feedback: `uidPrefix`/`uidPrefixes` read as singular and plural of one concept, but they are
scoped differently, which made the map hard to understand. `assemblyUidPrefixes` says what the key is
and removes the false symmetry.

Also reframes the docs around which option to reach for:

- `assemblyUidPrefixes` is the primary option. It is presented first, and the reason it has to be a
  shared map rather than a per entry setting is now stated: an entry mints UIDs for the APIs it
  *references* as well as the ones it documents, and those must match the UIDs produced by the entry
  documenting them.
- `uidPrefix` is documented as the narrow escape hatch for several entries building the same assembly
  name, with the trade-off spelled out (other entries cannot see it).
- Drops the example that set both options for the same assembly, which stated the same thing twice.
- Adds a table of which option applies when.

Fixes a bug found while renaming: `GetUidPrefixForCommentId` returned early unless the map was
populated, so crefs were left unprefixed when only `uidPrefix` was set. Both entry points now share an
`IsUidPrefixConfigured` check, and a new test covers crefs under a per entry prefix.

Snapshot output is byte identical to the previous commit.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: `assemblyUidPrefixes` and `uidPrefix` were an inconsistent pair of names for what is
one concept. There is now a single `uidPrefix` option that accepts either form, so the shape of the
value says which scope applies:

  "uidPrefix": { "MyLib": "Core" }   // by assembly name, shared by all metadata entries
  "uidPrefix": "Ef8"                // this entry's own assemblies

Both forms are still needed, and measuring on the linq2db docs build shows why. Replacing the object
form with a string on all 16 entries leaves cross-entry references unprefixed: 6690 references into the
core assembly across 163 pages resolve to UIDs no page has, so they render as plain text with no link
and no warning. The object form is combined across entries, which is what keeps those links alive; the
string form exists only because assemblies sharing an assembly name cannot be keyed by name.

`UidPrefixSetting` plus Newtonsoft and System.Text.Json converters follow the existing
`MarkdigExtensionSetting` pattern, so the value round trips as the bare string or object it was written
as. The JSON schema uses `oneOf`, and both forms are covered by the serialization parity test data and
by an end-to-end `MetadataCommandTest` case each.

Docs are restructured around the one option, with a subsection per form stating when to reach for it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…xOverride`

Review feedback: one option accepting a string or an object hid the fact that the two forms have
different scope. Two names make that visible, and `uidPrefixOverride` names its relationship to the map
rather than being its singular, which is what made the earlier `uidPrefix`/`uidPrefixes` pair confusing.

- `assemblyUidPrefixes` (map) is the option to reach for. It is project wide despite being written
  inside an entry: the maps of all entries are combined before any is processed.
- `uidPrefixOverride` (string) overrides it for one entry's assemblies, and is needed only when several
  entries build the same assembly name.

`UidPrefixSetting` and its two converters are gone with the merged option.

Docs now answer where the map goes when a project has many `src` entries, which the previous wording
left implicit: any entry works because the maps are combined, the whole map on the first entry is
recommended because it reads as one table, and the reason a per entry setting cannot replace it is
spelled out — an entry mints UIDs for the APIs it references as well as the ones it documents, and
getting those wrong loses links with no warning. Adds the rule of thumb that any assembly referenced by
another entry belongs in the map, and notes that conflicting mappings warn and keep the first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: the option was documented as project wide but written inside a `metadata` entry, which
put it out of place. It is now a top level `docfx.json` property, next to `metadata` and `rules`:

  {
    "assemblyUidPrefixes": { "MyLib": "Core" },
    "metadata": [ ... ]
  }

`DocfxConfig` carries it, `DotnetApiCatalog.Exec` takes it as an optional trailing parameter, and both
entry points pass it: the `docfx`/`docfx metadata` commands from `DocfxConfig`, and
`GenerateManagedReferenceYamlFiles` from the JSON it already parses itself. Validation splits into
`ValidateAssemblyUidPrefixes` for the project level map and `ValidateUidPrefixOverrides` for the per
entry overrides.

`uidPrefixOverride` stays on the entry, which is the point of it.

Docs now also state what the override does not fix, since that was not obvious:
- links from other entries into an override-prefixed assembly cannot be expressed, so it is only safe
  for assemblies nothing else in the project references
- it does not disambiguate two same-named assemblies inside one entry, because every assembly an entry
  documents gets the same prefix; narrowing the `src` glob is the fix there

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…grammar

Two review points.

**Default link target.** `uidPrefixOverride` cannot be seen by other entries, so references into an
assembly documented by several entries lose their links. No new option is needed for this: listing the
assembly in `assemblyUidPrefixes` as well already makes that prefix the fallback, because the override
only wins for the assemblies its own entry documents. So

  "assemblyUidPrefixes": { "MyLib.Ef": "Ef9" }

alongside `uidPrefixOverride` on the Ef8 and Ef9 entries keeps both versions' pages while pointing every
other entry's references at Ef9. Covered by a new test and documented, including the limitation that all
such links go to one chosen version.

**Prefix grammar.** The pattern required every segment to be a C# style identifier, which was my
invention rather than a real constraint, and it rejected plausible prefixes such as `net8.0` or `v1.2`.
The real constraints come from the UID becoming a file name, an xref key and an HTML anchor. Segments
after the first may now start with a digit:

  ^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z0-9_]+)*$

Still stricter than `globalNamespaceId`, which is inserted the same way and validates nothing at all, but
that strictness is deliberate: it keeps path and UID metacharacters out. The warning message now
describes the grammar instead of saying "identifier", and a test covers a digit leading segment.

Also adds the first coverage of the validation path itself: invalid map values, empty assembly names and
an invalid override are each reported as `InvalidUidPrefix` and dropped, and generation continues.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: the setup for pointing other entries at one of several same-named assemblies was buried
as a fourth level subsection under a "what the override does not fix" caveat, so a reader with per version
entries would not find it.

It is now a top level section, "Nominate a default version for links from elsewhere", framed as a
procedure rather than a caveat:

- states up front that one version has to be nominated, and that it goes in `assemblyUidPrefixes`
  *in addition to* the per entry `uidPrefixOverride`, not instead of it
- a table of which prefix is used when generating each thing, and why, so the composition of the two
  settings is explicit rather than asserted
- guidance on which version to nominate, normally the newest supported
- notes that hand written `<xref>` links are unaffected, since those name a UID literally

The `uidPrefixOverride` reference entry now links here instead of repeating a partial version of the
example.

Verified in the generated site that the anchor exists and that both the in page link and the cross page
link from the reference doc resolve to it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Review feedback: `assemblyUidPrefixes` was appended after `cancellationToken`, which breaks the
convention that a cancellation token is the last parameter. I had put it there to avoid touching existing
call sites; correctness wins over the smaller diff.

Only `MetadataCommand` passed both positionally and needed updating. The other call sites either stop
before the optional parameters or already use `assemblyUidPrefixes:` by name.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MaceWindu
MaceWindu force-pushed the fix/8966-uid-prefixes branch from 520a53a to dd95c86 Compare August 13, 2026 19:53
Replaces `assemblyUidPrefixes` / `uidPrefixOverride` with `assemblyUids` / `assemblyUidOverride`, which
join the assembly to the rest of the UID with `::` rather than a dot, and default the component to the
assembly's own name:

    linq2db.Tools::LinqToDB.Tools.Activity.ActivityStatistics

The prefix was doing two jobs, disambiguating the UID and labelling the namespace, and as a dot joined
segment it read as a namespace that does not exist. Titles said `Namespace linq2db.Tools.LinqToDB.Tools`
while the types in it reported the real `LinqToDB.Tools`, and authored xrefs had to name the made up one.

Display names now keep the namespace as declared, and the new per entry `assemblyLabel` decides how the
assembly is shown: `suffix` appends it to the namespace label, `none` never does, `page` names it on the
namespace page the way type pages do, and `auto` picks `suffix` for a flattened layout and `none` for a
nested one, where a per assembly root node already names it.

Consumers that had to follow the separator:

- `SymbolUrlResolver.GetDocfxUrl` split the comment id on every `:`, so a qualified UID collapsed to its
  assembly and every generated URL pointed at the same page.
- `XmlComment.ApplyAssemblyUid` joined crefs with a dot, which pointed them at UIDs no page has.
- `PathFriendlyId` maps `:` to `-`, one dash per character, matching `PathUtility.ToCleanUrlFileName`,
  which names the member pages of `memberLayout: separatePages` in the build stage.
- `YamlMetadataResolver` groups a nested table of contents by assembly, in a node that carries no UID so
  it needs no page, and no longer promotes a namespace out of it when it is the only one.
- `XrefInlineShortParser` accepts `::` so `@a::Ns.Type` does not end at the assembly.

Also fixes the global namespace: it is qualified like everything else, so two assemblies no longer share
the one page named by `globalNamespaceId`, and it finally has a display name instead of an empty table of
contents label (dotnet#9458).

Verified with the CSharp and SeedMarkdown snapshots, which are byte identical with the options unset.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@MaceWindu
MaceWindu force-pushed the fix/8966-uid-prefixes branch from dd95c86 to 9907932 Compare August 13, 2026 20:51
@MaceWindu MaceWindu closed this Sep 11, 2026
@MaceWindu
MaceWindu deleted the fix/8966-uid-prefixes branch September 11, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Duplicate namespaces

1 participant