Skip to content

Dotnet watch falls over frequently with "An item with the same key has already been added" #45455

@paulguz-datapa

Description

@paulguz-datapa

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Since upgrading our ASP.Net Core projects to .Net 9 (but leaving the others alone for now), we are experiencing the following error when running dotnet watch:

dotnet watch ❌ System.ArgumentException: An item with the same key has already been added. Key: 
C:\xxx\yyy\zzz\aaa\Language.csproj
   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.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.Watcher.Tools.IncrementalMSBuildWorkspace.UpdateProjectConeAsync(String rootProjectPath, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred

Language.csproj is a an assembly containing resource files.

Dotnet watch falls over at this point. It happens very frequently, making Hot Reload impossible.

Expected Behavior

Dotnet watch runs without failure

Steps To Reproduce

No response

Exceptions (if any)

System.ArgumentException: An item with the same key has already been added

.NET Version

9.0

Anything else?

This did not happen in .Net 8

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions