{"record":{"id":"f18b8f4f7582517c","repo":"stride3d/stride","slug":"this-settings-key-has-a-different-container-that-the-given","errorCode":null,"errorMessage":"This settings key has a different container that the given settings profile.","messagePattern":"This settings key has a different container that the given settings profile\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Settings/SettingsKey.cs","lineNumber":125,"sourceCode":"    /// <summary>\n    /// Notifes that the changes have been validated by <see cref=\"SettingsProfile.ValidateSettingsChanges\"/>.\n    /// </summary>\n    /// <param name=\"profile\">The profile in which the change has been validated.</param>\n    internal void NotifyChangesValidated(SettingsProfile profile)\n    {\n        ChangesValidated?.Invoke(this, new ChangesValidatedEventArgs(profile));\n    }\n\n    /// <summary>\n    /// Resolves the profile to use, returning the current profile if the given profile is null and checking the consistency of related <see cref=\"SettingsContainer\"/>.\n    /// </summary>\n    /// <param name=\"profile\">The profile to resolve.</param>\n    /// <returns>The resolved profile.</returns>\n    protected SettingsProfile ResolveProfile(SettingsProfile? profile = null)\n    {\n        profile ??= Container.CurrentProfile;\n        if (profile.Container != Container)\n            throw new ArgumentException(\"This settings key has a different container that the given settings profile.\");\n        return profile;\n    }\n}\n\n/// <summary>\n/// This class represents a <see cref=\"SettingsKey\"/> containing a value of the specified type <see cref=\"T\"/>.\n/// </summary>\n/// <typeparam name=\"T\">The type of value contained in this settings key.</typeparam>\npublic class SettingsKey<T> : SettingsKey\n{\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"SettingsKey{T}\"/> class.\n    /// </summary>\n    /// <param name=\"name\">The name of the settings key. Must be unique amongst an application.</param>\n    /// <param name=\"container\">The <see cref=\"SettingsContainer\"/> containing this <see cref=\"SettingsKey\"/>.</param>\n    public SettingsKey(UFile name, SettingsContainer container)\n        : this(name, container, default(T))\n    {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Settings/SettingsKey.cs#L107-L143","documentation":"SettingsKey instances belong to exactly one SettingsContainer, and ResolveProfile validates that any explicitly supplied profile comes from that same container before reading or writing through it. A profile from a different container would silently resolve keys in the wrong hierarchy, so the mismatch throws ArgumentException.","triggerScenarios":"Calling settingsKey.GetValue(profileFromOtherContainer) or SetValue(...) with a profile whose Container property differs from the key's Container; passing a profile created by another SettingsContainer instance (or another module's container).","commonSituations":"Two plugin/module systems each creating their own SettingsContainer and exchanging profiles; caching a profile from a container that was later recreated; copy-pasting settings access code across app domains.","solutions":["Use the overload without an explicit profile so ResolveProfile falls back to Container.CurrentProfile","Pass a profile obtained from the same container that owns the key (same Container reference)","Share a single SettingsContainer instance across modules instead of creating per-module containers"],"exampleFix":"// before\nmyKey.GetValue(profileFromOtherContainer);\n// after\nmyKey.GetValue(); // resolves against the key's own Container.CurrentProfile","handlingStrategy":"validation","validationCode":"if (profile != null && profile.Container != myKey.Container)\n    throw new ArgumentException(\"Profile belongs to a different SettingsContainer\");","typeGuard":"bool BelongsToKeyContainer(SettingsProfile p, SettingsKey key) => p.Container == key.Container;","tryCatchPattern":"try { value = myKey.GetValue(profile); }\ncatch (ArgumentException) { value = myKey.GetValue(); } // fall back to current profile","preventionTips":["Omit the explicit profile argument unless cross-profile reads are intentional","Share one SettingsContainer across modules","Never cache profiles from disposed or recreated containers"],"tags":["settings","argument-exception","container-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}