dotnet / dotnet/docfx

[Bug] .NET API bug: duplicate key in GenerateNestedTocStructure

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

Description

**Describe the bug**
My docfx build started failing because of a duplicate dictionary key error when generating a nested ToC structure. This started happening after I updated [PolySharp](https://github.com/Sergio0694/PolySharp) in my project to [1.14.0](https://github.com/Sergio0694/PolySharp/releases/tag/1.14.0).

**To Reproduce**

``` sh
git clone https://github.com/sliekens/gw2sdk.git
cd gw2sdk
git reset --hard c62c6f5167b6dbee83dbc73b1bf6d1a414fa945d
git clean -df
dotnet tool restore
dotnet docfx
```

**Expected behavior**
No crash

**Context (please complete the following information):**
- OS: Debian 12
- Docfx version: 2.74.1
- .NET version: .NET 8.0.100

- `docfx.json` config

```json
{
"metadata": [
{
"src": [
{
"src": "GW2SDK",
"files": [
"GW2SDK.csproj"
]
}
],
"dest": "docs/api",
"outputFormat": "mref",
"includePrivateMembers": false,
"disableGitFeatures": false,
"disableDefaultFilter": false,
"noRestore": false,
"namespaceLayout": "nested",
"memberLayout": "separatePages",
"enumSortOrder": "declaringOrder",
"allowCompilationErrors": false
}
],
"build": {
"content": [
{
"src": "docs",
"files": [
"index.md",
"toc.yml"
]
},
{
"src": "docs/guide",
"dest": "guide",
"files": [
"**.md",
"**/toc.yml"
]
},
{
"src": "docs/api",
"dest": "api",
"files": [
"**.yml",
"index.md"
]
}
],
"resource": [
{
"src": "docs",
"files": [
"images/**"
]
}
],
"output": "artifacts",
"fileMetadataFiles": [],
"postProcessors": [],
"keepFileLink": false,
"disableGitFeatures": false,
"template": [
"default",
"docs/templates/singulinkfx"
],
"globalMetadata": {
"_appTitle": "GW2SDK",
"_appName": "GW2SDK",
"_appLogoPath": "images/logo-50x50.png",
"_appFaviconPath": "images/logo-50x50.png",
"_appFooter": "Built with docfx, theme created by Singulink",
"_copyrightFooter": "© Steven Liekens. All rights reserved.",
"_enableSearch": true,
"_enableNewTab": true
}
}
}
```

- Exceptions

``` text
Creating output...
ArgumentException: An item with the same key has already been added. Key: System
at bool TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at void Add(TKey key, TValue value)
at MetadataItem GenerateNestedTocStructure(IEnumerable> namespaces, Dictionary allReferences) in YamlMetadataResolver.cs:105
at MetadataItem GenerateNestedToc(IEnumerable> namespaces, Dictionary allReferences) in YamlMetadataResolver.cs:162
at MetadataItem GenerateToc(Dictionary allMembers, Dictionary allReferences, NamespaceLayout namespaceLayout) in YamlMetadataResolver.cs:56
at MetadataModel ResolveMetadata(Dictionary allMembers, Dictionary allReferences, NamespaceLayout namespaceLayout) in YamlMetadataResolver.cs:33
at void g__ResolveAndExportYamlMetadata|2(Dictionary allMembers, Dictionary allReferences) in DotnetApiCatalog.ManagedReference.cs:51
at void CreateManagedReference((ValueTuple symbol) assemblies, ExtractMetadataConfig config, DotnetApiOptions options) in DotnetApiCatalog.ManagedReference.cs:45
at async Task g__Build|4_0(ExtractMetadataConfig config, DotnetApiOptions options) in DotnetApiCatalog.cs:123
at async Task Exec(MetadataJsonConfig config, DotnetApiOptions options, string configDirectory, string outputDirectory) in DotnetApiCatalog.cs:75
at void b__0() in DefaultCommand.cs:38
at int Run(LogOptions options, Action run) in CommandHelper.cs:44
at int Execute(CommandContext context, Options options) in DefaultCommand.cs:30
at Task Execute(CommandContext context, CommandSettings settings) in CommandOfT.cs:40
at Task Execute(CommandTree leaf, CommandTree tree, CommandContext context, ITypeResolver resolver, IConfiguration configuration) in CommandExecutor.cs:144
at async Task Execute(IConfiguration configuration, IEnumerable args) in CommandExecutor.cs:83
at async Task RunAsync(IEnumerable args) in CommandApp.cs:84
```

- .NET info

``` text
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.6c33ef20

Runtime Environment:
OS Name: debian
OS Version: 12
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.100/

.NET workloads installed:
Workload version: 8.0.100-manifests.6c33ef20
There are no installed workloads to display.

Host:
Version: 8.0.0
Architecture: x64
Commit: 5535e31a71

.NET SDKs installed:
8.0.100 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.14 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/usr/share/dotnet]

global.json file:
/workspaces/gw2sdk/global.json

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.