Issue with opening a dialog box automatically

Hi There

i am trying to open a dialog page when user goes to a specific page to start a process in WASM using the dialog component.

I can access the page without any issues if i open the dialog box with a button.

Any clues to what may be causing it? Any help greatly appreciated.
Cheers

code + error pasted below

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {

        await DialogService.OpenAsync<ReconcileBank>("Reconcile",
            new Dictionary<string, object>() { { "IsEdit", false } },
            new DialogOptions { Width = "900px", Height = "600px" }
            );
       
    }
    firstRender = false;
    StateHasChanged();
} 

Keep getting error/ the dialog gets stuck - in browser console i get the following error


dotnet.6.0.11.z8noe90rhw.js:1

   * Assertion: should not be reached at /__w/1/s/src/mono/mono/mini/interp/interp.c:3305

580850 @ dotnet.6.0.11.z8noe90rhw.js:1
_emscripten_asm_const_int @ dotnet.6.0.11.z8noe90rhw.js:1
$func111 @ 00971d3e:0x94bd
$func2230 @ 00971d3e:0x8eb83
$func3483 @ 00971d3e:0xcc2b7
$func3486 @ 00971d3e:0xcc346
$func3489 @ 00971d3e:0xcc3af
$func167 @ 00971d3e:0xc892
$func166 @ 00971d3e:0xbd73
$func2815 @ 00971d3e:0xabec4
$func1619 @ 00971d3e:0x6fc85
$func1617 @ 00971d3e:0x6fbf7
$func970 @ 00971d3e:0x50648
$func219 @ 00971d3e:0x1a44b
$func167 @ 00971d3e:0xce60
$func166 @ 00971d3e:0xbd73
$func2815 @ 00971d3e:0xabec4
$func1619 @ 00971d3e:0x6fc85
$func1623 @ 00971d3e:0x702f2
$mono_wasm_invoke_method @ 00971d3e:0x969f
Module._mono_wasm_invoke_method @ dotnet.6.0.11.z8noe90rhw.js:1
managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet @ managed__Microsoft_AspNetCore_Components_WebAssembly__Microsoft_AspNetCore_Components_WebAssembly_Services_DefaultWebAssemblyJSRuntime_BeginInvokeDotNet:19
beginInvokeDotNetFromJS @ blazor.webassembly.js:1
b @ blazor.webassembly.js:1
e.invokeMethodAsync @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
ve @ blazor.webassembly.js:1
we @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
(anonymous) @ blazor.webassembly.js:1
onGlobalEvent @ blazor.webassembly.js:1
blazor.webassembly.js:1

   Uncaught (in promise) ExitStatus

Anyone else faced this, or solved?

Most probably this is causing a loop.

Having StateHasChanged() in OnAfterRenderAsync is 100% causing endless loop. Put it inside the if (firstRender) block.

thank you so much for your reply.. i tired the following code, it seems to close the dialog, but if i hit refresh on the browser the dialog opens and stays open

   protected override async Task OnInitializedAsync()
{
    await base.OnInitializedAsync();
    DialogService.OnOpen += Open;
    DialogService.OnClose += Close;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        
        DialogService.Open<ReconcileBank>("Reconcile",
            new Dictionary<string, object>() { { "IsEdit", false } },
            new DialogOptions { Width = "900px", Height = "600px" }
            );
        firstRender = false;
        StateHasChanged();
    }
   
} 
public void Close(dynamic result)
{
}

public void Open(string title, Type type, Dictionary<string, object> parameters, DialogOptions options)
{

}

This is how your code works - browser refresh is again first render.

but does not stay open the 1st time - unless i have a break point but on continue it closes, am i missing something ? is the state has changed in the wrong place? i have tried both OpenAsync and Open

opening the dialog 2x works.. but why? really confused

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {

      await  DialogService.OpenAsync<ReconcileBank>("Reconcile",
            new Dictionary<string, object>() { { "IsEdit", false } },
            new DialogOptions { Width = "900px", Height = "500px" }
            );
        firstRender = false;
    }
    await  DialogService.OpenAsync<ReconcileBank>("Reconcile",
        new Dictionary<string, object>() { { "IsEdit", false } },
        new DialogOptions { Width = "900px", Height = "500px" }
        );
}

Experts, any insight? Cheers

any help will be appreciated.