stride3d/stride · error · ArgumentException
Cannot set the profile as current if it's not registered to…
Error message
Cannot set the profile as current if it's not registered to the container
What it means
SettingsContainer.CreateSettingsProfile accepts flags setAsCurrent and registerInContainer independently, but a profile only tracks settings keys registered after its creation if it lives in the container. Making an unregistered profile current would hand out a profile that silently misses later keys, so the combination is rejected with ArgumentException.
Solutions
- Pass setAsCurrent: false when registerInContainer is false
- Pass registerInContainer: true if the profile really must become current
- Create the profile registered, then manually set CurrentProfile and later unload it via UnloadSettingsProfile when done
Example fix
// before container.CreateSettingsProfile(setAsCurrent: true, registerInContainer: false); // after container.CreateSettingsProfile(setAsCurrent: true, registerInContainer: true);
Defensive patterns
Strategy: validation
Validate before calling
if (setAsCurrent && !registerInContainer)
throw new ArgumentException("setAsCurrent requires registerInContainer: true", nameof(setAsCurrent)); Try / catch
try { container.CreateSettingsProfile(true, registerInContainer: false); }
catch (ArgumentException e) { logger.Warn(e.Message); } Prevention
- Never combine setAsCurrent:true with registerInContainer:false
- Use named arguments at call sites to make flag combinations explicit
- Document that current profiles must live in the container
When it happens
Trigger: Calling CreateSettingsProfile(setAsCurrent: true, registerInContainer: false) — including the file-loading overload with the same flags.
Common situations: Creating a temporary/derived profile for one-off reads and accidentally asking for it to become CurrentProfile; API refactors where registerInContainer defaulted differently in an older version.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- The default profile cannot be unloaded
- This settings key has a different container that the given…
- Cannot add an asset with an empty Id
- Cannot add an asset that is already added to another package
- Asset location [ ] must be relative and not absolute (not…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/330b5457d94da74f.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Design/Settings/SettingsContainer.cs:97
{
return [.. settingsKeys.Values];
}
/// <summary>
/// Creates a new settings profile.
/// </summary>
/// <param name="setAsCurrent">If <c>true</c>, the created profile will also be set as <see cref="CurrentProfile"/>.</param>
/// <param name="parent">The parent profile of the settings to create. If <c>null</c>, the default profile will be used.</param>
/// <param name="registerInContainer">If true, the profile will be registered in this container. Otherwise it will be disconnected from the container.</param>
/// <returns>A new instance of the <see cref="SettingsProfile"/> class.</returns>
/// <remarks>
/// If the profile is not registered to the container, it won't be able to receive <see cref="SettingsKey"/> that are registered after its
/// creation. If the profile is registered to the container, <see cref="UnloadSettingsProfile"/> must be call in order to unregister it.
/// </remarks>
[NotNull]
public SettingsProfile CreateSettingsProfile(bool setAsCurrent, SettingsProfile? parent = null, bool registerInContainer = true)
{
if (setAsCurrent && !registerInContainer) throw new ArgumentException("Cannot set the profile as current if it's not registered to the container", nameof(setAsCurrent));
var profile = new SettingsProfile(this, parent ?? RootProfile);
if (registerInContainer)
{
lock (SettingsLock)
{
profileList.Add(profile);
if (setAsCurrent)
CurrentProfile = profile;
}
}
return profile;
}
/// <summary>
/// Loads a settings profile from the given file.
/// </summary>View on GitHub (pinned to 96fad776d2)