-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Persistent state not persisting if [PersistentState] applied to non-public property
Expected Behavior
PersistentStateAttribute should work with private properties
Steps To Reproduce
Counter page:
@page "/counter"
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
[PersistentState]
private int? CurrentCount { get; set; }
protected override void OnInitialized()
{
CurrentCount ??= Random.Shared.Next(100);
}
private void IncrementCount()
{
CurrentCount++;
}
}
Exceptions (if any)
log error when navigate to /counter page:
fail: Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager[1000]
There was an error executing a callback while pausing the application.
System.InvalidOperationException: Property CurrentCount not found on type BlazorPersistentStatePlayground.Client.Pages.Counter
at Microsoft.AspNetCore.Components.Infrastructure.PersistentStateValueProvider.PropertyGetterFactory(ValueTuple`2 key)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.AspNetCore.Components.Infrastructure.PersistentStateValueProvider.ResolvePropertyGetter(Type type, String propertyName)
at Microsoft.AspNetCore.Components.Infrastructure.PersistentStateValueProvider.<>c__DisplayClass13_0.<Subscribe>b__0()
at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<TryPauseAsync>g__TryExecuteCallback|18_0(Func`1 callback, ILogger`1 logger)
.NET Version
10.0.0-preview.7.25380.108
Anything else?
No response
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion