In a server-interactive page in Blazor 8, the ApplicationContextAccessor will sometimes pick the aspnetcore IContextManager when it should use the Blazor server context manager.
The constructor needs to walk backwards through the list of registered IContextManager services so it selects the one that is valid and is also the most recently added to the list.
var managers = contextManagerList.ToList();
for (int i = managers.Count - 1; i >= 0; i--)
{
if (managers[i].IsValid)
{
ContextManager = managers[i];
break;
}
}
ContextManager ??= new Core.ApplicationContextManagerAsyncLocal();
In a server-interactive page in Blazor 8, the
ApplicationContextAccessorwill sometimes pick the aspnetcoreIContextManagerwhen it should use the Blazor server context manager.The constructor needs to walk backwards through the list of registered
IContextManagerservices so it selects the one that is valid and is also the most recently added to the list.