stride3d/stride · error · ArgumentException

The default profile cannot be unloaded

Error message

The default profile cannot be unloaded

What it means

The RootProfile is the built-in default profile of a SettingsContainer; it always exists and must never be removed from profileList. UnloadSettingsProfile rejects it with ArgumentException because unloading the root would leave the container without a base profile for key resolution.

Solutions

  1. Skip the RootProfile in any unload loop (compare with container.RootProfile)
  2. Only unload profiles returned from CreateSettingsProfile/LoadSettingsProfile with registerInContainer: true
  3. Guard the call: if (profile != container.RootProfile) container.UnloadSettingsProfile(profile);

Example fix

// before
foreach (var p in allProfiles) container.UnloadSettingsProfile(p);
// after
foreach (var p in allProfiles.Where(p => p != container.RootProfile)) container.UnloadSettingsProfile(p);
Defensive patterns

Strategy: validation

Validate before calling

if (profile == container.RootProfile) return; // nothing to unload

Try / catch

try { container.UnloadSettingsProfile(profile); }
catch (ArgumentException) { /* profile is the root: ignore */ }

Prevention

When it happens

Trigger: Calling container.UnloadSettingsProfile(container.RootProfile), typically by holding a reference obtained from CreateSettingsProfile's default parent chain or from the RootProfile property itself.

Common situations: Tearing down settings and iterating over profiles without excluding the root; caching a profile reference that actually points to RootProfile; lifecycle code unloading everything registered in a container.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at sources/core/Stride.Core.Design/Settings/SettingsContainer.cs:205

            SettingsYamlSerializer.Default.Deserialize(stream, settingsFile);
        }
        catch (Exception e)
        {
            Logger.Error($"Error while loading settings file [{filePath}].", e);
        }

        var handler = SettingsFileLoaded;
        handler?.Invoke(null, new SettingsFileLoadedEventArgs(filePath));
    }

    /// <summary>
    /// Unloads a profile that was previously loaded.
    /// </summary>
    /// <param name="profile">The profile to unload.</param>
    public void UnloadSettingsProfile(SettingsProfile profile)
    {
        if (profile == RootProfile)
            throw new ArgumentException("The default profile cannot be unloaded");
        if (profile == CurrentProfile)
            throw new InvalidOperationException("Unable to unload the current profile.");
        lock (SettingsLock)
        {
            profileList.Remove(profile);
        }
    }

    /// <summary>
    /// Saves the given settings profile to a file at the given path.
    /// </summary>
    /// <param name="profile">The profile to save.</param>
    /// <param name="filePath">The path of the file.</param>
    /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>
    public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)
    {
#if NET6_0_OR_GREATER
        ArgumentNullException.ThrowIfNull(profile);

View on GitHub (pinned to 96fad776d2)