dotnet / dotnet/aspnetcore

Improve error report on HotReloadAgent

Open
#49,941 4 comments 0 reactions 0 assignees View on GitHub
area-blazor bug feature-hot-reload Pillar: Dev Experience Priority:1
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

Hot Reload may fail while applying code changes, [see this example](https://github.com/dotnet/runtime/issues/90037) on applying changes while debugging in VS. I tried with .NET 7.0.203.

While the javascript stack showed useful information regarding the error:
```
Error: System.TypeLoadException: EnC: we do not support patching of existing table cols. token=0x0200000f
at System.Reflection.Metadata.MetadataUpdater.ApplyUpdate(:7222/Assembly assembly, ReadOnlySpan`1 metadataDelta, ReadOnlySpan`1 ilDelta, ReadOnlySpan`1 pdbDelta)
at Microsoft.Extensions.HotReload.HotReloadAgent.ApplyDeltas(:7222/IReadOnlyList`1 deltas)
at Microsoft.AspNetCore.Components.WebAssembly.HotReload.WebAssemblyHotReload.ApplyHotReloadDelta(:7222/String moduleIdString, Byte[] metadataDelta, Byte[] ilDelta, Byte[] pdbBytes)
...
```

This is what the user sees in the output window:
```
20:46 51.50 BlazorApp14.Server (Web assembly): Sending updates to running application
20:46 51.56 BlazorApp14.Server (Web assembly): [Error] Applying updates failed:
20:46 51.56 BlazorApp14.Server (Web assembly): [Error] Applying updates failed: The following error occurred when trying to apply your edits to the running application.
20:46 51.57 Exception thrown for Apply Code Updates: 0x80131500 - The following error occurred when trying to apply your edits to the running application. The following error occurred when trying to apply your edits to the running application.
20:46 51.57 Stack trace for WebToolsException:
at Microsoft.WebTools.ProjectSystem.Components.HotReload.ProjectHotReloadSession.d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Debugger.Shared.Utilities.LoggerExtensions.d__3.MoveNext()
20:46 51.57 An unexpected error has occurred, any pending updates have been discarded.
```

**Problems**
1. The error is reported twice.
2. The exception itself has the following message:
`"The following error occurred when trying to apply your edits to the running application. The following error occurred when trying to apply your edits to the running application."`

**Proposal**
We should propagate the error message back to the user. If I understand correctly, [the current code only logs the error to the debug output](https://github.com/dotnet/aspnetcore/blob/9344b153c00d64c2fec3c07b8ecd178dd666732e/src/Components/WebAssembly/WebAssembly/src/HotReload/HotReloadAgent.cs#L222C12-L222C33), and not back to the user.

This is specifically for scenarios where we are applying code changes with a hot reload agent.

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.