Blazor Serialize state for services DirectScopedResolvedFromRootException issue.
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
```cs
var builder = WebApplication.CreateBuilder(args);
var service = builder.Services;
service.AddHttpContextAccessor();
builder.Services.AddScoped();
// Add services to the container.
service
.AddRazorComponents()
.RegisterPersistentService(RenderMode.InteractiveAuto)
.AddInteractiveServerComponents()
.AddInteractiveWebAssemblyComponents()
.AddAuthenticationStateSerialization(options =>
{
options.SerializeAllClaims = true;
});
```
```cs
public class CounterTracker
{
[PersistentState]
public int CurrentCount { get; set; }
public void IncrementCount()
{
CurrentCount++;
}
}
```
```error
blazor.web.f7fxoh55ae.js:1 ManagedError: AggregateException_ctor_DefaultMessage (DirectScopedResolvedFromRootException, DigitalVault.Blazor.Client.CounterTracker, scoped)
```
I follow the same Instruction in this official [documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/state-management/prerendered-state-persistence?view=aspnetcore-10.0#serialize-state-for-services), still i getting the `DirectScopedResolvedFromRootException`.
Contributor guide
Research direction
Start with the minimal Blazor application and the documented “Serialize state for services” guidance linked in the issue. Reproduce the DirectScopedResolvedFromRootException using CounterTracker and its service registration, then determine why the shown setup resolves the scoped service from the root. Done means the documented setup runs without the exception and CounterTracker state is persisted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- full-stack
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100