From fdf7f58466c48c3ba042fd279bd1c4b02cf42549 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Mon, 4 Mar 2019 10:42:03 +0000 Subject: [PATCH] Handle asynchrony during app startup on WebAssembly. Fixes #8079 --- .../src/Hosting/WebAssemblyHostExtensions.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostExtensions.cs b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostExtensions.cs index 988ea88ac0..d08162a590 100644 --- a/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostExtensions.cs +++ b/src/Components/Blazor/Blazor/src/Hosting/WebAssemblyHostExtensions.cs @@ -1,6 +1,8 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; + namespace Microsoft.AspNetCore.Blazor.Hosting { /// @@ -19,7 +21,16 @@ namespace Microsoft.AspNetCore.Blazor.Hosting /// public static void Run(this IWebAssemblyHost host) { - host.StartAsync().GetAwaiter().GetResult(); + // Behave like async void, because we don't yet support async-main properly on WebAssembly. + // However, don't actualy make this method async, because we rely on startup being synchronous + // for things like attaching navigation event handlers. + host.StartAsync().ContinueWith(task => + { + if (task.Exception != null) + { + Console.WriteLine(task.Exception); + } + }); } } -} \ No newline at end of file +}