Closed
Description
Found in version 6.0.100-preview.5.21254.10
Repro
- Create new Blazor Server app targeting .NET 6.0
- In "Index.razor" add the following block:
<EditForm Model="widget">
<DataAnnotationsValidator />
Widget Name: <InputText @bind-Value="widget.Name" />
</EditForm>
@code {
Widget widget = new Widget();
class Widget
{
public string Name { get; set; }
};
}
- Run the app
- In the console output see the following exception:
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HM8FAL8PSLLA", Request id "0HM8FAL8PSLLA:00000001": An unhandled exception was thrown by the application.
System.InvalidOperationException: The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.
at Microsoft.AspNetCore.Components.Dispatcher.AssertAccess() in Microsoft.AspNetCore.Components.dll:token 0x60000b2+0x12
at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment) in Microsoft.AspNetCore.Components.dll:token 0x6000232+0x0
at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged() in Microsoft.AspNetCore.Components.dll:token 0x6000098+0x2d
at Microsoft.AspNetCore.Components.Forms.InputBase`1.OnValidateStateChanged(Object sender, ValidationStateChangedEventArgs eventArgs) in Microsoft.AspNetCore.Components.Web.dll:token 0x6000150+0x6
at Microsoft.AspNetCore.Components.Forms.EditContext.NotifyValidationStateChanged() in Microsoft.AspNetCore.Components.Forms.dll:token 0x6000018+0x16
at Microsoft.AspNetCore.Components.Forms.EditContextDataAnnotationsExtensions.DataAnnotationsEventSubscriptions.Dispose() in Microsoft.AspNetCore.Components.Forms.dll:token 0x6000062+0x39
at Microsoft.AspNetCore.Components.Forms.DataAnnotationsValidator.System.IDisposable.Dispose() in Microsoft.AspNetCore.Components.Forms.dll:token 0x600000b+0x0
at Microsoft.AspNetCore.Components.Rendering.ComponentState.Dispose() in Microsoft.AspNetCore.Components.dll:token 0x60002cd+0x15
at Microsoft.AspNetCore.Components.RenderTree.Renderer.Dispose(Boolean disposing) in Microsoft.AspNetCore.Components.dll:token 0x6000242+0x92
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception) in Microsoft.AspNetCore.Mvc.ViewFeatures.dll:token 0x6000060+0x0
at Microsoft.AspNetCore.Components.RenderTree.Renderer.<Dispose>g__NotifyExceptions|65_1(List`1 exceptions) in Microsoft.AspNetCore.Components.dll:token 0x600024a+0x2a
at Microsoft.AspNetCore.Components.RenderTree.Renderer.Dispose(Boolean disposing) in Microsoft.AspNetCore.Components.dll:token 0x6000242+0xec
at Microsoft.AspNetCore.Components.RenderTree.Renderer.DisposeAsync() in Microsoft.AspNetCore.Components.dll:token 0x6000244+0x9b
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope.<DisposeAsync>g__Await|16_0(Int32 i, ValueTask vt, List`1 toDispose) in Microsoft.Extensions.DependencyInjection.dll:token 0x6000128+0x6e
at Microsoft.AspNetCore.Http.Features.RequestServicesFeature.<DisposeAsync>g__Awaited|9_0(RequestServicesFeature servicesFeature, ValueTask vt) in Microsoft.AspNetCore.Http.dll:token 0x6000228+0x5b
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.<FireOnCompleted>g__ProcessEvents|227_0(HttpProtocol protocol, Stack`1 events) in Microsoft.AspNetCore.Server.Kestrel.Core.dll:token 0x6000b1e+0x81