You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WebToolsException when using hot reload to apply change to Blazor WebAssembly app #90037
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
@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>)
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))
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
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
Updatemdv 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)
Activity
mkArtakMSFT commentedon Aug 4, 2023
@BillHiebert has looked into this and have determined the below is the stack trace:
mkArtakMSFT commentedon Aug 4, 2023
@lambdageek, @lewing this seems to be a hot-reload related issue in WebAssembly runtime.
lambdageek commentedon Aug 4, 2023
Interesting. It looks like the EnC delta has a modification to a TypeDef row. I guess there are two possibilities:
apply_enclog_pass1for 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))
isadorasophia commentedon Aug 4, 2023
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:
Which takes a longer time to triage/route/investigate these kind of issues
lambdageek commentedon Aug 7, 2023
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
mdvshows 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:
Generation 1:
Merge remote-tracking branch 'origin/main' into fix-dotnetgh-90037