{"record":{"id":"330b5457d94da74f","repo":"stride3d/stride","slug":"cannot-set-the-profile-as-current-if-it-s-not-registered-to","errorCode":null,"errorMessage":"Cannot set the profile as current if it's not registered to the container","messagePattern":"Cannot set the profile as current if it's not registered to the container","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Settings/SettingsContainer.cs","lineNumber":97,"sourceCode":"    {\n        return [.. settingsKeys.Values];\n    }\n\n    /// <summary>\n    /// Creates a new settings profile.\n    /// </summary>\n    /// <param name=\"setAsCurrent\">If <c>true</c>, the created profile will also be set as <see cref=\"CurrentProfile\"/>.</param>\n    /// <param name=\"parent\">The parent profile of the settings to create. If <c>null</c>, the default profile will be used.</param>\n    /// <param name=\"registerInContainer\">If true, the profile will be registered in this container. Otherwise it will be disconnected from the container.</param>\n    /// <returns>A new instance of the <see cref=\"SettingsProfile\"/> class.</returns>\n    /// <remarks>\n    /// If the profile is not registered to the container, it won't be able to receive <see cref=\"SettingsKey\"/> that are registered after its\n    /// creation. If the profile is registered to the container, <see cref=\"UnloadSettingsProfile\"/> must be call in order to unregister it.\n    /// </remarks>\n    [NotNull]\n    public SettingsProfile CreateSettingsProfile(bool setAsCurrent, SettingsProfile? parent = null, bool registerInContainer = true)\n    {\n        if (setAsCurrent && !registerInContainer) throw new ArgumentException(\"Cannot set the profile as current if it's not registered to the container\", nameof(setAsCurrent));\n\n        var profile = new SettingsProfile(this, parent ?? RootProfile);\n\n        if (registerInContainer)\n        {\n            lock (SettingsLock)\n            {\n                profileList.Add(profile);\n                if (setAsCurrent)\n                    CurrentProfile = profile;\n            }\n        }\n        return profile;\n    }\n\n    /// <summary>\n    /// Loads a settings profile from the given file.\n    /// </summary>","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Settings/SettingsContainer.cs#L79-L115","documentation":"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.","triggerScenarios":"Calling CreateSettingsProfile(setAsCurrent: true, registerInContainer: false) — including the file-loading overload with the same flags.","commonSituations":"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.","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"],"exampleFix":"// before\ncontainer.CreateSettingsProfile(setAsCurrent: true, registerInContainer: false);\n// after\ncontainer.CreateSettingsProfile(setAsCurrent: true, registerInContainer: true);","handlingStrategy":"validation","validationCode":"if (setAsCurrent && !registerInContainer)\n    throw new ArgumentException(\"setAsCurrent requires registerInContainer: true\", nameof(setAsCurrent));","typeGuard":null,"tryCatchPattern":"try { container.CreateSettingsProfile(true, registerInContainer: false); }\ncatch (ArgumentException e) { logger.Warn(e.Message); }","preventionTips":["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"],"tags":["settings","argument-exception","config"],"backgroundTag":"conflicting-config-options","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"}