2

I'm struggling with finding the reason of exception which is thrown after the entire page is reloaded.

It's a Blazor application (server side, .NET 8). In the header, there is a select list which allows user to choose the country. After the selected country is changed, the entire page should be reloaded.

To achieve that I've tried to call:

NavigationManager.NavigateTo(NavigationManager.Uri, true, true);

Admittedly, the page is reloaded, but after a second the NullReferenceException is thrown. Since it doesn't point to any part of my code, I can't figure out what exactly is causing it.

Exception details (no InnerException):

System.NullReferenceException: Object reference not set to an instance of an object.

Call Stack:

Microsoft.AspNetCore.Components.Server.dll!Microsoft.AspNetCore.Components.Server.Circuits.RemoteJSRuntime.EndInvokeDotNet(Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo, Microsoft.JSInterop.Infrastructure.DotNetInvocationResult invocationResult) Line 201 C# Microsoft.JSInterop.dll!Microsoft.JSInterop.Infrastructure.DotNetDispatcher.EndInvokeDotNetAfterTask(System.Threading.Tasks.Task task, Microsoft.JSInterop.JSRuntime jsRuntime, Microsoft.JSInterop.Infrastructure.DotNetInvocationInfo invocationInfo) Line 164 C# Microsoft.JSInterop.dll!Microsoft.JSInterop.Infrastructure.DotNetDispatcher.BeginInvokeDotNet.AnonymousMethod__0(System.Threading.Tasks.Task t) Line 124 C# System.Private.CoreLib.dll!System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(System.Threading.Thread threadPoolThread, System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) Line 264 C# System.Private.CoreLib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot, System.Threading.Thread threadPoolThread) Line 2349 C# System.Private.CoreLib.dll!System.Threading.ThreadPoolWorkQueue.Dispatch() Line 913 C# System.Private.CoreLib.dll!System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() Line 102 C#

It seems that _clientProxy instance in else clause is NULL but I have no idea how to prevent that:

protected override void EndInvokeDotNet(DotNetInvocationInfo invocationInfo, in DotNetInvocationResult invocationResult)
{
    if (!invocationResult.Success)
    {
        Log.InvokeDotNetMethodException(_logger, in invocationInfo, invocationResult.Exception);
        string arg;
        if (_options.DetailedErrors)
        {
            arg = invocationResult.Exception.ToString();
        }
        else
        {
            arg = "There was an exception invoking '" + invocationInfo.MethodIdentifier + "'";
            if (invocationInfo.AssemblyName != null)
            {
                arg = arg + " on assembly '" + invocationInfo.AssemblyName + "'";
            }
            arg += ". For more details turn on detailed exceptions in 'CircuitOptions.DetailedErrors'";
        }
        _clientProxy.SendAsync("JS.EndInvokeDotNet", invocationInfo.CallId, false, arg);
    }
    else
    {
        Log.InvokeDotNetMethodSuccess(_logger, in invocationInfo);
        _clientProxy.SendAsync("JS.EndInvokeDotNet", invocationInfo.CallId, true, invocationResult.ResultJson); // The exception is thrown here
    }
}

Additionaly, I tried to replace NavigationManager with the plain call of JavaScript function:

await JavaScriptRuntime.InvokeVoidAsync("location.reload");

but it gives the same result.

What's even weirder to me is that if I just refresh the page manually (for example by hitting the Enter on the address bar), everything works as intended and no exception is thrown. I thought that calling NavigateTo with forceLoad = true is an equivalent to manual refresh of entire page.

Finally, I tried to reproduce the problem in a new project generated from Visual Studio template, but unfortunately no problem is observable in such a project. I even tried to edit some value with ProtectedLocalStorage since I use it in my actual application as well but it works smoothly.

All things considered, it seems that there is a problem with running some JS statement but for some reason it doesn't appear when the page is reloaded manually.

Do you have any idea how to find more detailed information about the exception? Since both call stack and abovementioned _clientProxy don't point to any part of my code, I'm not sure how to solve the issue.

3
  • I con’t repeat your question based on the information you provided,can you provide more code snippets? Commented Aug 8, 2024 at 6:13
  • Unfortunately, it can be tricky. Especially because I know that it's not reproducible in a totally new project created from VS template. That is why, I hoped it's possible to access more detailed information from the exception which is thrown by .NET framework's library. If I manage to reproduce the problem in a independent project, I will send the update. Commented Aug 9, 2024 at 18:52
  • Similar problem after update linq data and refresh components... Commented Feb 7 at 12:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.