dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.74k stars 1.07k forks source link

dotnet watch Fails in Blazor #44384

Open j4587698 opened 1 month ago

j4587698 commented 1 month ago

Describe the bug

dotnet watch command fails when a Blazor project references any multi-target framework project

To Reproduce

BlazorApp1.zip dotnet watch run this project and change any razor file.

Exceptions (if any)

dotnet watch ⌚ File added: .\Components\Pages\Home.razor~ dotnet watch ⌚ File changed: .\Components\Pages\Home.razor dotnet watch ⏳ Waiting for a file to change before restarting dotnet... dotnet watch ❌ System.ArgumentException: An item with the same key has already been added. Key: D:\dotnet\BlazorApp1\ClassLibrary1\ClassLibrary1.csproj at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1 source, Func2 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()

Further technical details

dotnet --info .NET SDK: Version: 9.0.100-rc.2.24474.11 Commit: 315e1305db Workload version: 9.0.100-manifests.cea95dba MSBuild version: 17.12.0-preview-24473-03+fea15fbd1

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\

.NET workloads installed: Configured to use loose manifests when installing new manifests. There are no installed workloads to display.

Host: Version: 9.0.0-rc.2.24473.5 Architecture: x64 Commit: 990ebf52fc

.NET SDKs installed: 6.0.101 [C:\Program Files\dotnet\sdk] 6.0.402 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk] 8.0.100 [C:\Program Files\dotnet\sdk] 9.0.100-rc.2.24474.11 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0-rc.2.24474.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0-rc.2.24473.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.0-rc.2.24474.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: None

Environment variables: Not set

global.json file: Not found

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

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

Any IDE

jburman commented 1 week ago

Getting a similar dictionary insert error on the release version of .net 9, but different stack trace. (not a multi-targeted project). I can't consistently repro it yet.

dotnet watch ⏳ Waiting for a file to change before restarting dotnet... dotnet watch ❌ System.ArgumentException: An item with the same key has already been added. Key: 4998 at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at System.Collections.Generic.Dictionary2.Add(TKey key, TValue value) at Microsoft.CodeAnalysis.Emit.DeltaMetadataWriter.GetDelta(Compilation compilation, Guid encId, MetadataSizes metadataSizes) at Microsoft.CodeAnalysis.Compilation.SerializeToDeltaStreams(CommonPEModuleBuilder moduleBeingBuilt, EmitBaseline baseline, DefinitionMap definitionMap, SymbolChanges changes, Stream metadataStream, Stream ilStream, Stream pdbStream, ArrayBuilder1 updatedMethods, ArrayBuilder1 changedTypes, DiagnosticBag diagnostics, Func2 testSymWriterFactory, String pdbFilePath, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.CSharp.Emit.EmitHelpers.EmitDifference(CSharpCompilation compilation, EmitBaseline baseline, IEnumerable1 edits, Func2 isAddedSymbol, Stream metadataStream, Stream ilStream, Stream pdbStream, CompilationTestData testData, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.Compilation.EmitDifference(EmitBaseline baseline, IEnumerable1 edits, Func2 isAddedSymbol, Stream metadataStream, Stream ilStream, Stream pdbStream, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.EditAndContinue.EditSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider solutionActiveStatementSpanProvider, UpdateId updateId, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.EditAndContinue.DebuggingSession.EmitSolutionUpdateAsync(Solution solution, ActiveStatementSpanProvider activeStatementSpanProvider, CancellationToken cancellationToken) at Microsoft.CodeAnalysis.ExternalAccess.Watch.Api.WatchHotReloadService.GetUpdatesAsync(Solution solution, Func2 isRunningProject, CancellationToken cancellationToken) at Microsoft.DotNet.Watcher.Tools.CompilationHandler.HandleFileChangesAsync(Func`3 restartPrompt, 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

.NET SDK: Version: 9.0.100 Commit: 59db016f11 Workload version: 9.0.100-manifests.c6f19616 MSBuild version: 17.12.7+5b8665660

Runtime Environment: OS Name: Windows OS Version: 10.0.26100 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100\

Eptagone commented 2 days ago

I'm having exactly the same error with my project after updating. It only happens when I run my project with dotnet watch.