{"record":{"id":"67a815315e849c45","repo":"dotnet/aspnetcore","slug":"the-nameof-parameterview-instance-can-no-longer","errorCode":null,"errorMessage":"The {nameof(ParameterView)} instance can no longer be read because it has expired. {nameof(ParameterView)} can only be read synchronously and must not be stored for later use.","messagePattern":"The (.+?) instance can no longer be read because it has expired\\. (.+?) can only be read synchronously and must not be stored for later use\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/Rendering/ParameterViewLifetime.cs","lineNumber":25,"sourceCode":"{\n    private readonly RenderBatchBuilder _owner;\n    private readonly int _stamp;\n\n    public static readonly ParameterViewLifetime Unbound;\n\n    public ParameterViewLifetime(RenderBatchBuilder owner)\n    {\n        _owner = owner;\n        _stamp = owner.ParameterViewValidityStamp;\n    }\n\n    public void AssertNotExpired()\n    {\n        // If _owner is null, this instance is default(ParameterViewLifetime), which is\n        // the same as ParameterViewLifetime.Unbound. That means it never expires.\n        if (_owner != null && _owner.ParameterViewValidityStamp != _stamp)\n        {\n            throw new InvalidOperationException($\"The {nameof(ParameterView)} instance can no longer be read because it has expired. {nameof(ParameterView)} can only be read synchronously and must not be stored for later use.\");\n        }\n    }\n}\n","sourceCodeStart":7,"sourceCodeEnd":29,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/Rendering/ParameterViewLifetime.cs#L7-L29","documentation":"A ParameterView obtained during one render batch was read after the batch advanced (its validity stamp no longer matches the owning RenderBatchBuilder). ParameterView is a synchronous, snapshot-style struct; storing it across renders or async gaps and reading it later triggers this InvalidOperationException from ParameterViewLifetime.AssertNotExpired.","triggerScenarios":"Storing a ParameterView in a field and reading it in OnAfterRenderAsync, a timer callback, or after an await. Capturing `parameters` from SetParametersAsync into a Task and indexing it later. Passing ParameterView to another component/method that defers the read.","commonSituations":"Manually caching parameters for async work. Forgetting to copy needed values out of ParameterView at the top of SetParametersAsync. Component frameworks that try to forward ParameterView to children outside the synchronous scope.","solutions":["Extract every value you need from ParameterView synchronously at the top of SetParametersAsync into local/field copies.","Never store the ParameterView itself; if you must defer, copy into a Dictionary<string,object?> first.","Re-fetch parameters via a fresh read in the next lifecycle call instead of reusing the snapshot."],"exampleFix":"// before\npublic override async Task SetParametersAsync(ParameterView parameters)\n{\n    _savedParams = parameters; // stored\n    await DoWork();\n    var x = _savedParams.GetValueOrDefault<int>(\"Count\"); // expired!\n}\n\n// after\npublic override async Task SetParametersAsync(ParameterView parameters)\n{\n    _count = parameters.GetValueOrDefault<int>(\"Count\");\n    await DoWork();\n}","handlingStrategy":"validation","validationCode":"// Always copy out values synchronously\npublic override Task SetParametersAsync(ParameterView parameters)\n{\n    _count = parameters.GetValueOrDefault<int>(nameof(Count));\n    _name = parameters.GetValueOrDefault<string>(nameof(Name));\n    return base.SetParametersAsync(parameters);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never store ParameterView in a field.","Extract all needed values at the top of SetParametersAsync before any await.","If you must defer, copy into a Dictionary<string,object?> snapshot first."],"tags":["blazor","parameters","lifecycle","async","parameter-view"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}