stride3d/stride · error · ArgumentException

This settings key has a different container that the given…

Error message

This settings key has a different container that the given settings profile.

What it means

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.

Solutions

  1. Use the overload without an explicit profile so ResolveProfile falls back to Container.CurrentProfile
  2. Pass a profile obtained from the same container that owns the key (same Container reference)
  3. Share a single SettingsContainer instance across modules instead of creating per-module containers

Example fix

// before
myKey.GetValue(profileFromOtherContainer);
// after
myKey.GetValue(); // resolves against the key's own Container.CurrentProfile
Defensive patterns

Strategy: validation

Validate before calling

if (profile != null && profile.Container != myKey.Container)
    throw new ArgumentException("Profile belongs to a different SettingsContainer");

Type guard

bool BelongsToKeyContainer(SettingsProfile p, SettingsKey key) => p.Container == key.Container;

Try / catch

try { value = myKey.GetValue(profile); }
catch (ArgumentException) { value = myKey.GetValue(); } // fall back to current profile

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f18b8f4f7582517c. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.Design/Settings/SettingsKey.cs:125

    /// <summary>
    /// Notifes that the changes have been validated by <see cref="SettingsProfile.ValidateSettingsChanges"/>.
    /// </summary>
    /// <param name="profile">The profile in which the change has been validated.</param>
    internal void NotifyChangesValidated(SettingsProfile profile)
    {
        ChangesValidated?.Invoke(this, new ChangesValidatedEventArgs(profile));
    }

    /// <summary>
    /// Resolves the profile to use, returning the current profile if the given profile is null and checking the consistency of related <see cref="SettingsContainer"/>.
    /// </summary>
    /// <param name="profile">The profile to resolve.</param>
    /// <returns>The resolved profile.</returns>
    protected SettingsProfile ResolveProfile(SettingsProfile? profile = null)
    {
        profile ??= Container.CurrentProfile;
        if (profile.Container != Container)
            throw new ArgumentException("This settings key has a different container that the given settings profile.");
        return profile;
    }
}

/// <summary>
/// This class represents a <see cref="SettingsKey"/> containing a value of the specified type <see cref="T"/>.
/// </summary>
/// <typeparam name="T">The type of value contained in this settings key.</typeparam>
public class SettingsKey<T> : SettingsKey
{
    /// <summary>
    /// Initializes a new instance of the <see cref="SettingsKey{T}"/> class.
    /// </summary>
    /// <param name="name">The name of the settings key. Must be unique amongst an application.</param>
    /// <param name="container">The <see cref="SettingsContainer"/> containing this <see cref="SettingsKey"/>.</param>
    public SettingsKey(UFile name, SettingsContainer container)
        : this(name, container, default(T))
    {

View on GitHub (pinned to 96fad776d2)