This is a known bug and is resolved in the upcoming release of Blazor Preview 3. [Issue Resolved]
[wwwroot/index.html]
<script>
window.interopDuringOnInit = function () {
return "Hello World";
}
</script>
[Razor]
@code {
string Greeting;
protected override async Task OnInitializedAsync()
{
try
{
Greeting = await JSRuntime.InvokeAsync<string>("interopDuringOnInit");
}
catch (Exception ex)
{
Console.WriteLine("Could not invoke interop during OnInit, " + ex.ToString());
}
}
}
Refer to the thread Tasks returned from JSRuntime.InvokeAsync during OnInitAsync never finishes for more information.
Share with