dotnet / dotnet/sdk

10.0.300 regression: dotnet watch crashes with "An item with the same key has already been added"

Open
#54,552 4 comments 11 reactions 1 assignee Claimed by @tmat View on GitHub
Area-Watch untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

Using `dotnet watch` with our project worked with SDK 10.0.203, but crashes with 10.0.300.

### Steps to reproduce

I have yet been unable to reproduce this issue in other solutions.

### Expected behavior

`dotnet watch` starts the application

### Actual behavior

```
$> Microsoft_CodeAnalysis_EditAndContinue_LogDir=/tmp/HotReloadLog dotnet watch --project "Frontend" --verbose
dotnet watch ⌚ Working directory: '/home/david/projects/rrs/signalbox-web'
dotnet watch ⌚ Watching with Hot Reload.
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
dotnet watch 💡 Press Ctrl+R to restart.
dotnet watch 🔨 Restoring /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj ...
dotnet watch 🚀 Launched '/home/david/.dotnet/dotnet' with arguments 'restore /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj --property:NuGetInteractive=true -consoleLoggerParameters:NoSummary': process id 1468665
Wiederherstellung abgeschlossen (1,1s)

Erstellen von Erfolgreich in 1,3s
dotnet watch ⌚ Process id 1468665 ran for 1531ms and exited with exit code 0.
dotnet watch 🔨 Project graph loaded in 0,4s.
dotnet watch 🔨 Building /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj ...
dotnet watch 🚀 Launched '/home/david/.dotnet/dotnet' with arguments 'build /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj --property:NuGetInteractive=true --framework net10.0 --no-restore': process id 1468811
LibDelegateDict net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibDelegateDict/bin/Debug/net10.0/LibDelegateDict.dll
Dus500Connector net10.0 Erfolgreich (0,2s) → /home/david/projects/rrs/signalbox-web/Dus500Connector/bin/Debug/net10.0/Dus500Connector.dll
LibEstwParser net10.0 Erfolgreich (0,2s) → /home/david/projects/rrs/signalbox-web/LibEstwParser/bin/Debug/net10.0/LibEstwParser.dll
LibRds net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibRds/bin/Debug/net10.0/LibRds.dll
LibTf2000 net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibTf2000/bin/Debug/net10.0/LibTf2000.dll
LibDatabase net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibDatabase/bin/Debug/net10.0/LibDatabase.dll
LibDusMetrics net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibDusMetrics/bin/Debug/net10.0/LibDusMetrics.dll
Frontend net10.0 Erfolgreich (0,4s) → bin/Debug/net10.0/Frontend.dll

Erstellen von Erfolgreich in 1,5s
dotnet watch ⌚ Process id 1468811 ran for 1721ms and exited with exit code 0.
dotnet watch ⌚ Loading projects ...
dotnet watch ❌ An unexpected error occurred: System.ArgumentException: An item with the same key has already been added. Key: ProjectInstanceId { ProjectPath = /home/david/.nuget/packages/nerdbank.gitversioning/3.9.50/build/PrivateP2PCaching.proj, TargetFramework = }
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
at System.Linq.Enumerable.SpanToDictionary[TSource,TKey,TElement](ReadOnlySpan`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
at Microsoft.DotNet.Watch.EvaluationResult.TryCreateAsync(LoadedProjectGraph projectGraph, ILogger logger, GlobalOptions globalOptions, EnvironmentOptions environmentOptions, String mainProjectTargetFramework, Boolean restore, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.Program.RunAsync()
```
No file gets created in `/tmp/HotReloadLog`

### Is this a regression?

Yes, in 10.0.203:
```
$> Microsoft_CodeAnalysis_EditAndContinue_LogDir=/tmp/HotReloadLog dotnet watch --project "Frontend" --verbose
dotnet watch ⌚ Working directory: '/home/david/projects/rrs/signalbox-web'
dotnet watch ⌚ Watching with Hot Reload.
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
dotnet watch 💡 Press Ctrl+R to restart.
dotnet watch 🔨 Building /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj ...
dotnet watch 🚀 Launched '/home/david/.dotnet/dotnet' with arguments 'build /home/david/projects/rrs/signalbox-web/Frontend/Frontend.csproj -consoleLoggerParameters:NoSummary;Verbosity=minimal --property:NuGetInteractive=true': process id 1477235
Wiederherstellung abgeschlossen (1,0s)
Dus500Connector net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/Dus500Connector/bin/Debug/net10.0/Dus500Connector.dll
LibEstwParser net10.0 Erfolgreich (0,0s) → /home/david/projects/rrs/signalbox-web/LibEstwParser/bin/Debug/net10.0/LibEstwParser.dll
LibDelegateDict net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibDelegateDict/bin/Debug/net10.0/LibDelegateDict.dll
LibRds net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibRds/bin/Debug/net10.0/LibRds.dll
LibDatabase net10.0 Erfolgreich (0,1s) → /home/david/projects/rrs/signalbox-web/LibDatabase/bin/Debug/net10.0/LibDatabase.dll
LibTf2000 net10.0 Erfolgreich (0,3s) → /home/david/projects/rrs/signalbox-web/LibTf2000/bin/Debug/net10.0/LibTf2000.dll
LibDusMetrics net10.0 Erfolgreich (0,2s) → /home/david/projects/rrs/signalbox-web/LibDusMetrics/bin/Debug/net10.0/LibDusMetrics.dll
Frontend net10.0 Erfolgreich (0,1s) → bin/Debug/net10.0/Frontend.dll

Erstellen von Erfolgreich in 2,4s
dotnet watch ⌚ Process id 1477235 ran for 2610ms and exited with exit code 0.
dotnet watch ⌚ Evaluating projects ...
dotnet watch ⌚ Watching 682 file(s) for changes
dotnet watch ⌚ Evaluation completed in 2,5s.
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/LibDelegateDict'
dotnet watch ⌚ Exclusion glob: '**\node_modules\**;node_modules\**;**\jspm_packages\**;jspm_packages\**;**\bower_components\**;bower_components\**;**\packages.lock.json;bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/LibTf2000'
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/Dus500Connector'
dotnet watch ⌚ Exclusion glob: '**\node_modules\**;node_modules\**;**\jspm_packages\**;jspm_packages\**;**\bower_components\**;bower_components\**;**\packages.lock.json;bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/Frontend'
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store;bin\Debug/net8.0/publish//**' under project '/home/david/projects/rrs/signalbox-web/LibRds'
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/LibDusMetrics'
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/LibDatabase'
dotnet watch ⌚ Exclusion glob: 'bin\Debug//**;obj\Debug//**;bin\/**;obj\/**;bin\Debug/net10.0/publish//**;**/*.user;**/*.*proj;**/*.sln;**/*.slnx;**/*.vssscc;**/.DS_Store' under project '/home/david/projects/rrs/signalbox-web/LibEstwParser'
dotnet watch ⌚ Excluded directory: '/home/david/projects/rrs/signalbox-web/LibRds/obj/Debug'
dotnet watch ⌚ Application kind: WebApplication.
dotnet watch 🔃 [Frontend (net10.0)] Using browser-refresh middleware
dotnet watch 🔃 [Frontend (net10.0)] Refresh server running at wss://localhost:33009,ws://localhost:42781.
dotnet watch ⌚ dotnet-watch is configured to launch a browser on ASP.NET Core application startup.
dotnet watch 🔥 [Frontend (net10.0)] Waiting for application to connect to pipe 96f5589ac2fb46e08b12a1122b26e47b.
dotnet watch 🚀 [Frontend (net10.0)] Launched '/home/david/.dotnet/dotnet' with arguments 'run --no-build -e DOTNET_WATCH=1 -e DOTNET_WATCH_ITERATION=1 -e DOTNET_MODIFIABLE_ASSEMBLIES=debug -e DOTNET_STARTUP_HOOKS=/home/david/.dotnet/sdk/10.0.203/DotnetTools/dotnet-watch/10.0.203/tools/net10.0/any/hotreload/net6.0/Microsoft.AspNetCore.Watch.BrowserRefresh.dll:/home/david/.dotnet/sdk/10.0.203/DotnetTools/dotnet-watch/10.0.203/tools/net10.0/any/hotreload/net10.0/Microsoft.Extensions.DotNetDeltaApplier.dll -e DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME=96f5589ac2fb46e08b12a1122b26e47b -e ASPNETCORE_AUTO_RELOAD_WS_ENDPOINT=wss://localhost:33009,ws://localhost:42781 -e ASPNETCORE_AUTO_RELOAD_WS_KEY=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxz4cLK6dGBoX513uzf7FoeNk5LPgbpGLZS50BsLNaNqstdN7ZPJugxQOxSwLFJUzzw9R8x2uOP+ZVKB4QH2AJ8+0gs2OGMC4viCOLRzy+GvIqGDCQzscs6TRvcmvUisSikEQv+yWp+lV8zC73DZAsilMfoFmJyZr6bja4GKarHqHA0q9NDpIvwyKHMBR/T0pqzSdnYfXhxXTfN3zj0CjYvTfjefN9C55CTV6v2VqSDAb4QDuMGD4WBsF08wM2DkShQrMm88cg7r8pHKbsSmZwTg5seBohCpUHOgD5AOYeFSVI+Mv7JfIP99g+p1y25LW8TfJh6uakilL8+nfLe3OvQIDAQAB -e ASPNETCORE_AUTO_RELOAD_VDIR=/ -e ASPNETCORE_HOSTINGSTARTUPASSEMBLIES=Microsoft.AspNetCore.Watch.BrowserRefresh --project Frontend': process id 1477509
Die Starteinstellungen von Frontend/Properties/launchSettings.json werden verwendet…
dotnet watch 🔥 [Frontend (net10.0)] Capabilities: 'Baseline AddMethodToExistingType AddStaticFieldToExistingType AddInstanceFieldToExistingType NewTypeDefinition ChangeCustomAttributes UpdateParameters GenericUpdateMethod GenericAddMethodToExistingType GenericAddFieldToExistingType AddFieldRva AddExplicitInterfaceImplementation'.
dotnet watch ⌚ Loading projects ...
2026-06-02 11:59:43.2371|INFO|Program|Intializing RDS-Plattform Frontend 0.46.108-dev (Config: Debug)
...
```

### Are there any workarounds?

_No response_

### dotnet --info output

```console
.NET SDK:
Version: 10.0.300
Commit: caa81fa497
Workload version: 10.0.300-manifests.b47d7e23
MSBuild version: 18.6.3+caa81fa49

Laufzeitumgebung:
OS Name: fedora
OS Version: 44
OS Platform: Linux
RID: linux-x64
Base Path: /home/david/.dotnet/sdk/10.0.300/

Installierte .NET-Workloads:
Es sind keine installierten Workloads zum Anzeigen vorhanden.
Für die Verwendung von workload sets bei der Installation neuer Manifeste konfiguriert.
Es sind keine Workloadsätze installiert. Führen Sie „dotnet workload restore“ aus, um einen Workloadsatz zu installieren.

Host:
Version: 10.0.8
Architecture: x64
Commit: 94ea82652c

.NET SDKs installed:
10.0.300 [/home/david/.dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.27 [/home/david/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.16 [/home/david/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.8 [/home/david/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.27 [/home/david/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.16 [/home/david/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.8 [/home/david/.dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/home/david/.dotnet]

global.json file:
/home/david/projects/rrs/signalbox-web/global.json

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

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

### IDE version

_No response_

### Other details

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.