dotnet / dotnet/sdk

dotnet watch crashes with a FormatException when editing a scoped CSS file

Open
#54,915 0 comments 1 reaction 2 assignees 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

In a solution where an ASP.NET Core server hosts a Blazor WebAssembly app, running dotnet watch on the server project (which launches both) causes the watcher to crash whenever a scoped CSS file is edited (for example WebApp/Layout/MainLayout.razor.css). The crash is a System.FormatException raised while computing static asset updates.

* Reproduced on .NET 10 and on the latest .NET 11 preview (`11.0.100-preview.5.26302.115`).

The crash only happens in the hosted setup, where `dotnet watch` runs on the server project. Running `dotnet watch` on the `WebApp` project on its own no longer crashes on a scoped CSS edit, which might suggest the fix already landed in the Gateway package but does not cover the hosted scenario.

### Steps to reproduce

A repository to reproduce this issue can be found here: [julian-baumann/blazor-reload-issue](https://github.com/julian-baumann/blazor-reload-issue)

1. Clone the `julian-baumann/blazor-reload-issue` repository. It contains two projects:
* `BackendServer` (ASP.NET Core host)
* `WebApp` (Blazor WebAssembly, served by the host)
2. Run `dotnet watch` on the `BackendServer` project so both projects start together.
3. Once the app is running, edit any scoped CSS file, such as `WebApp/Layout/MainLayout.razor.css`.

### Expected behavior

The scoped CSS change is hot reloaded and `dotnet watch` keeps running.

### Actual behavior

`dotnet watch` terminates the child processes and then crashes with the following output:

```
dotnet watch ⌚ Waiting for changes
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5166
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: /BlazorReloadIssue/BackendServer
dotnet watch ⌚ File change: Update '/BlazorReloadIssue/WebApp/Layout/NavMenu.razor.css'.
dotnet watch ⌚ File updated: /BlazorReloadIssue/WebApp/Layout/NavMenu.razor.css
dotnet watch ⌚ Solution after document update: v2
dotnet watch ⌚ Terminating remaining child processes.
dotnet watch ⌚ [BackendServer (net11.0)] Terminating process 88189 (SIGTERM).
dotnet watch ⌚ [BackendServer (net11.0)] Waiting for process 88189 to exit within 5s.
info: Microsoft.Hosting.Lifetime[0]
Application is shutting down...
dotnet watch ⌚ [BackendServer (net11.0)] Process id 88189 ran for 6298ms and exited with exit code 0.
dotnet watch ⌚ [BackendServer (net11.0)] Exited
dotnet watch 🔥 [BackendServer (net11.0)] Disposing agent communication pipe
dotnet watch ❌ An unexpected error occurred: System.FormatException: Input string was not in a correct format. Failure to parse near offset 25. Expected an ASCII digit.
at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
at Microsoft.DotNet.Watch.MessageDescriptor`1.GetMessage(TArgs args)
at Microsoft.DotNet.Watch.Extensions.<>c__3`1.b__3_0(LogState`1 state, Exception _)
at Microsoft.DotNet.Watch.LoggerFactory.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.DotNet.Watch.Extensions.Log[TArgs](ILogger logger, MessageDescriptor`1 descriptor, TArgs args)
at Microsoft.DotNet.Watch.CompilationHandler.GetStaticAssetUpdatesAsync(HotReloadProjectUpdatesBuilder builder, IReadOnlyList`1 files, EvaluationResult evaluationResult, Stopwatch stopwatch, CancellationToken cancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
at Microsoft.DotNet.Watch.Program.RunAsync()
```

### Is this a regression?

_No response_

### Are there any workarounds?

_No response_

### dotnet --info output

```console
.NET SDK:
Version: 11.0.100-preview.5.26302.115
Commit: f7b4c5716f
Workload version: 11.0.100-preview.5.26309.3
MSBuild version: 18.8.0-preview-26302-115+f7b4c5716

Runtime Environment:
OS Name: Mac OS X
OS Version: 27.0
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/11.0.100-preview.5.26302.115/

.NET workloads installed:
[macos]
Installation Source: SDK 11.0.100-preview.5
Manifest Version: 26.5.11546-net11-p5/11.0.100-preview.5
Manifest Path: /usr/local/share/dotnet/sdk-manifests/11.0.100-preview.5/microsoft.net.sdk.macos/26.5.11546-net11-p5/WorkloadManifest.json
Install Type: FileBased

Configured to use workload sets when installing new manifests.

Host:
Version: 11.0.0-preview.5.26302.115
Architecture: arm64
Commit: f7b4c5716f

.NET SDKs installed:
9.0.305 [/usr/local/share/dotnet/sdk]
10.0.300 [/usr/local/share/dotnet/sdk]
11.0.100-preview.5.26302.115 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 11.0.0-preview.5.26302.115 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 11.0.0-preview.5.26302.115 [/usr/local/share/dotnet/shared/Microsoft.NETCore.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
```

### IDE version

_No response_

### Other details

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.