docfx metadata command failed with ArgumentException at this line
ArgumentException: An item with the same key has already been added. Key: Root.Datastore
at bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at void Add(TKey key, TValue value)
at MetadataItem GenerateNestedTocStructure(IEnumerable<KeyValuePair<string, MetadataItem>> namespaces,
Dictionary<string, ReferenceItem> allReferences) in YamlMetadataResolver.cs:105
This problem is occurred when following conditions are met
Referencing empty namespace with <see cref=""> tag.
Using "namespaceLayout": "nested"
Using "outputFormat": "mref"
What's changed in this PR
This PR changes allReferences.Add logic to allReferences.TryAdd method to skip when key already exists.
For example. When /// <see cref="Root.Datastore"/> comment exists.
allReferences contains this information as ReferenceItem (N:Root.Datastore).
Additionally I've added post-process logics to overwrite empty namespace reference.
It's required because Empty namespace don't generate HTML page.
So <see cref=""/> link is not works for empty namespace.
This PR intended to fix issue reported at https://github.com/dotnet/docfx/issues/2532#issuecomment-2181542930
Details of problem
docfx metadata
command failed withArgumentException
at this lineThis problem is occurred when following conditions are met
<see cref="">
tag.What's changed in this PR
This PR changes
allReferences.Add
logic toallReferences.TryAdd
method to skip when key already exists.For example. When
/// <see cref="Root.Datastore"/>
comment exists.allReferences
contains this information asReferenceItem
(N:Root.Datastore
).Additionally I've added post-process logics to overwrite empty namespace reference. It's required because Empty namespace don't generate HTML page. So
<see cref=""/>
link is not works for empty namespace.Test I've manually tested following tests by using DocFxUndefinedReferenceBugDemo content.
docfx metadata
command successfully completed.<see cref=""
link to empty namespace is rendered as plain text.<see cref=""
link to other namespace is rendered as normal link.