Skip to content

Improve error report on HotReloadAgent #49941

Closed

Description

@isadorasophia

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hot Reload may fail while applying code changes, see this example 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.<ApplyUpdatesAsync>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.<LogOnExceptionAsync>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, and not back to the user.

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

Activity

  1. ghost added
    area-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI
    on Aug 8, 2023
  2. lambdageek commented on Aug 9, 2023

    @lambdageek
    Member

    If I understand correctly, the current code only logs the error to the debug output, and not back to the user.

    This is due to

    Interlocked.CompareExchange(ref _hotReloadAgent, new HotReloadAgent(m => Debug.WriteLine(m)), null);

    a log callback that sends results back through the hot reload websocket would be better...


    Additionally, we would ideally extend the try clause to also cover this line

    MetadataUpdater.ApplyUpdate(assembly, item.MetadataDelta, item.ILDelta, item.PdbBytes ?? ReadOnlySpan<byte>.Empty);

    So that we log exceptios from MetadataUpdater.ApplyUpdate (which Mono can throw sometimes if there are issues).

  3. added
    area-blazorIncludes: Blazor, Razor Components
    and removed
    area-commandlinetoolsIncludes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI
    on Aug 17, 2023
  4. added
    bugThis issue describes a behavior which is not expected - a bug.
    on Aug 23, 2023
  5. deleted a comment from on Aug 23, 2023
  6. captainsafia commented on Aug 24, 2023

    @captainsafia
    Contributor

    @isadorasophia Can you clarify what you mean by "back to the user" here?

    If I understand correctly, the current code only logs the error to the debug output, and not back to the user.

    AFAIK, the logging behavior here seems to actually be coming from VS's hot reload logic here.

  7. modified the milestones: 8.0-rc2, on Sep 28, 2023
  8. removed this from the milestone on Oct 3, 2023
  9. 6 remaining items

  10. added
    Priority:2Work that is important, but not critical for the release
    on Jan 23, 2024
  11. added
    Priority:1Work that is critical for the release, but we could probably ship without
    and removed
    Priority:2Work that is important, but not critical for the release
    on Jan 23, 2024
  12. PreethikaSelvam commented on Jul 22, 2026

    @PreethikaSelvam
    Contributor

    Hi @isadorasophia,

    This issue was reproducible with the reported SDK version, .NET 7.0.203. However, it could not be reproduced with later SDK versions, including .NET 8, .NET 9, and .NET 10. Based on our validation, the issue appears to have been resolved in newer releases. We recommend upgrading to the latest supported .NET SDK version to avoid encountering this issue.

  13. oroztocil commented on Oct 22, 2026

    @oroztocil
    Member

    @PreethikaSelvam Thanks for the investigation.

    Closing this issue. It only reproduced with the .NET 7 SDK, and the related code no longer exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Pillar: Dev ExperiencePriority:1Work that is critical for the release, but we could probably ship withoutarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-hot-reloadThis issue is related to the Hot Reload feaature

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions