Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Javier ...
Working on validating/updating the code demos in articles for the new persistent component state model and hit a gremlin 😈.
Expected Behavior
No exception and retain the generated value in a counter component that uses the new model.
Steps To Reproduce
Akin to what you show in the OP of the PR at #60634 (but I made the property public
), BUT this demo should set an initial value on initialization to demo how a value created on the server can be held for final rendering.
This issue is really just asking how to approach this scenario more so than a bug report. I don't think it's a bug, of course! 😄
Vanilla BWA 10.0 Preview 3 with global Interactive Server rendering.
Counter2.razor
:
@page "/counter-2"
@inject ILogger<Counter2> Logger
<PageTitle>Prerendered Counter 2</PageTitle>
<h1>Prerendered Counter 2</h1>
<p role="status">Current count: @CurrentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
[SupplyParameterFromPersistentComponentState]
public int CurrentCount { get; set; }
protected override void OnInitialized()
{
CurrentCount = Random.Shared.Next(100);
Logger.LogInformation("CurrentCount set to {Count}", CurrentCount);
}
private void IncrementCount() => CurrentCount++;
}
BTW ... I'm also not sure if we're supposed to account for the restoration of a persisted value during initialization ...
if (CurrentCount == 0)
{
CurrentCount = Random.Shared.Next(100);
}
Exceptions (if any)
Output ...
info: BlazorSample.Components.Pages.Counter2[0]
CurrentCount set to 77
fail: Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager[1000]
There was an error executing a callback while pausing the application.
System.ArgumentException: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
at System.Reflection.RuntimeMethodInfo.CreateDelegateInternal(Type delegateType, Object firstArgument, DelegateBindingFlags bindingFlags)
at Microsoft.AspNetCore.Components.Reflection.PropertyGetter..ctor(Type targetType, PropertyInfo property)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.PropertyGetterFactory(ValueTuple`2 key)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.ResolvePropertyGetter(Type type, String propertyName)
at Microsoft.AspNetCore.Components.SupplyParameterFromPersistentComponentStateValueProvider.<>c__DisplayClass11_0.<Subscribe>b__0()
at Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.<TryPauseAsync>g__TryExecuteCallback|18_0(Func`1 callback, ILogger`1 logger)
info: BlazorSample.Components.Pages.Counter2[0]
CurrentCount set to 43
.NET Version
10.0.100-preview.3.25201.16
Anything else?
No response