Skip to content

WebToolsException when using hot reload to apply change to Blazor WebAssembly app #90037

Closed

Description

@vsfeedback

This issue has been moved from a ticket on Developer Community.


I got the following error when trying to hot reload a change to my Blazor WebAssemlby app:

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.

Repro steps:

  • Create an ASP.NET Core hosted Blazor WebAssembly app using .NET 7
  • Add Shared/MyLayout.razor to the Client project
@inherits LayoutComponentBase
<h1>MyLayout</h1>
<main>
    @Body
</main>
  • Update Index.razor to include @layout MyLayout just below the @page directive
  • Run the app without debugging
  • Remove the @layout MyLayout directive from Index.Razor
  • Hot reload the change to the running app

Original Comments

Feedback Bot on 7/23/2023, 05:58 PM:

(private comment, text removed)

Feedback Bot on 7/24/2023, 01:36 AM:

(private comment, text removed)


Original Solutions

(no solutions)

Activity

  1. mkArtakMSFT commented on Aug 4, 2023

    @mkArtakMSFT

    @BillHiebert has looked into this and have determined the below is the stack trace:

    The failure is this:
    
    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)
       at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.InvokeSynchronously(:7222/JSRuntime jsRuntime, DotNetInvocationInfo& callInfo, IDotNetObjectReference objectReference, String argsJson)
       at Microsoft.JSInterop.Infrastructure.DotNetDispatcher.Invoke(:7222/JSRuntime jsRuntime, DotNetInvocationInfo& invocationInfo, String argsJson)
       at Microsoft.AspNetCore.Components.WebAssembly.Services.DefaultWebAssemblyJSRuntime.InvokeDotNet(:7222/String assemblyName, String methodIdentifier, String dotNetObjectId, String argsJson)
        at qi (dotnet.7.0.9.spglg51993.js:5:80665)
        at Ji (dotnet.7.0.9.spglg51993.js:5:80549)
        at _Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet (_Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_InvokeDotNet:30:5)
        at Object.invokeDotNetFromJS (blazor.webassembly.js:1:45224)
        at g (blazor.webassembly.js:1:1621)
        at e.invokeMethod (blazor.webassembly.js:1:2670)
        at Vt.Ke._internal.applyHotReload (blazor.webassembly.js:1:58767)
        at aspnetcore-browser-refresh.js:140:35
        at Array.forEach (<anonymous>)
    
  2. ghost added
    needs-area-label
    on Aug 4, 2023
  3. ghost added
    untriaged
    on Aug 4, 2023
  4. added
    area-EnC-mono
    and removed
    needs-area-label
    on Aug 4, 2023
  5. mkArtakMSFT commented on Aug 4, 2023

    @mkArtakMSFT

    @lambdageek, @lewing this seems to be a hot-reload related issue in WebAssembly runtime.

  6. added this to the 8.0.0 milestone on Aug 4, 2023
  7. removed
    untriaged
    on Aug 4, 2023
  8. lambdageek commented on Aug 4, 2023

    @lambdageek
    Member

    Interesting. It looks like the EnC delta has a modification to a TypeDef row. I guess there are two possibilities:

    • (unlikely) there's some legitimate reason to modify a TypeDef row for a supported edit (maybe TypeAttributes ?)
    • (more likely) in apply_enclog_pass1 for the TypeDef case we have logic for "add field" and "add method" that validates that the edit is what we expected, but not for "add property" and "add event" - they just fall through to an error. Probably they should be allowed.

    Assuming it's the latter - we should just allow "add property" and "add event". The bigger question is why our tests didn't catch this. We do have some "add stuff to existing classes" testcases. But for some reason they don't hit the same assertions?

    (I haven't tried to repro the failure - just going by what's in the error message that Bill uncovered #90037 (comment))

  9. isadorasophia commented on Aug 4, 2023

    @isadorasophia

    Not exactly related to this issue specifically, but could we find a way to propagate the javascript stack to the managed exception? The user only sees the following on 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.
    

    Which takes a longer time to triage/route/investigate these kind of issues

  10. lambdageek commented on Aug 7, 2023

    @lambdageek
    Member

    So the source change (looking at the generated .cs files for the razor delta) here is the deletion of a custom attribute from a class definition. Interestingly we had a test in the runtime for deleting a custom attribute from a method. And that works. But if I change the test to delete an attribute from a class, it crashes the same way. We're definitely not handling something properly

    Update mdv shows the delta doesn't actually change any rows of the TypeDef. But it does send an update anyway. So it's the former case in my comment above #90037 (comment)

    Generation 0:

    3: 'ClassWithCustomAttributeDelete' (#e1)  'System.Reflection.Metadata.ApplyUpdate.Test' (#47b)  nil (TypeDef)  0x0100001a (TypeRef)  nil         nil                    0x0600000a-0x0600000d  0x00100001 (AutoLayout, AnsiClass, Class, Public, BeforeFieldInit)  n/a        n/a          
    

    Generation 1:

    1: 'ClassWithCustomAttributeDelete' (#4d6/1:2d)  'System.Reflection.Metadata.ApplyUpdate.Test' (#59a/1:f1)  nil (TypeDef)  0x0100001e/1:3 (TypeRef)  nil         n/a (EnC)  n/a (EnC)  0x00100001 (AutoLayout, AnsiClass, Class, Public, BeforeFieldInit)  n/a        n/a          
    
  11. ghost added
    in-pr
    on Aug 8, 2023
  12. ghost removed
    in-pr
    on Aug 9, 2023
  13. ghost locked as resolved and limited conversation to collaborators on Sep 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-EnC-mono

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions