{"record":{"id":"04d1a5c1aa90c92d","repo":"dotnet/efcore","slug":"the-object-name-has-been-removed-from-the-mode-04d1a5","errorCode":null,"errorMessage":"The object '{name}' has been removed from the model.","messagePattern":"The object '(.+?)' has been removed from the model\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs","lineNumber":61,"sourceCode":"        if (rowsAffected)\n        {\n            _direction = ParameterDirection.Output;\n            _directionConfigurationSource = ConfigurationSource.Explicit;\n        }\n\n        _builder = new InternalStoredProcedureParameterBuilder(this, storedProcedure.Builder.ModelBuilder);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual InternalStoredProcedureParameterBuilder Builder\n    {\n        [DebuggerStepThrough]\n        get => _builder ?? throw new InvalidOperationException(CoreStrings.ObjectRemovedFromModel(Name));\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual bool IsInModel\n        => _builder is not null\n            && StoredProcedure.IsInModel;\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/StoredProcedureParameter.cs#L43-L79","documentation":"Accessing the Builder of a StoredProcedureParameter that was removed from the model throws, because its internal _builder field has been nulled. This indicates the parameter is no longer part of the live metadata graph.","triggerScenarios":"Holding a stale StoredProcedureParameter reference after the procedure (or the parameter) was removed via model configuration, then reading .Builder or invoking a builder API on it.","commonSituations":"Convention code that caches parameter references across a model rebuild; calling RemoveParameter / reconfiguring the procedure while another code path still references the old parameter object; snapshotting metadata and using it after the model was finalized.","solutions":["Stop caching parameter metadata objects across model mutations; re-query from the current model.","Guard access with the IsInModel property before touching .Builder.","Re-fetch the parameter via StoredProcedure.FindParameter(name) on the current procedure.","Review convention ordering so code does not run after the parameter has been removed."],"exampleFix":"// before\nvar oldParam = proc.Parameters[0];\nproc.RemoveParameter(oldParam.Name);\nvar b = oldParam.Builder; // throws\n\n// after\nvar param = proc.FindParameter(name);\nif (param is { IsInModel: true })\n{\n    var b = param.Builder;\n}","handlingStrategy":"validation","validationCode":"if (parameter.IsInModel)\n{\n    var builder = parameter.Builder;\n}","typeGuard":"static bool IsLiveParameter(StoredProcedureParameter p)\n    => p.IsInModel;","tryCatchPattern":null,"preventionTips":["Never cache parameter metadata across model mutations.","Re-query parameters from the live procedure each time you need them.","Check IsInModel before any builder access."],"tags":["ef-core","stored-procedure","metadata","lifecycle","internal-api"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}