{"record":{"id":"88f7ce680bb7602a","repo":"stride3d/stride","slug":"unable-to-unload-the-current-profile","errorCode":null,"errorMessage":"Unable to unload the current profile.","messagePattern":"Unable to unload the current profile\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Settings/SettingsContainer.cs","lineNumber":207,"sourceCode":"        catch (Exception e)\n        {\n            Logger.Error($\"Error while loading settings file [{filePath}].\", e);\n        }\n\n        var handler = SettingsFileLoaded;\n        handler?.Invoke(null, new SettingsFileLoadedEventArgs(filePath));\n    }\n\n    /// <summary>\n    /// Unloads a profile that was previously loaded.\n    /// </summary>\n    /// <param name=\"profile\">The profile to unload.</param>\n    public void UnloadSettingsProfile(SettingsProfile profile)\n    {\n        if (profile == RootProfile)\n            throw new ArgumentException(\"The default profile cannot be unloaded\");\n        if (profile == CurrentProfile)\n            throw new InvalidOperationException(\"Unable to unload the current profile.\");\n        lock (SettingsLock)\n        {\n            profileList.Remove(profile);\n        }\n    }\n\n    /// <summary>\n    /// Saves the given settings profile to a file at the given path.\n    /// </summary>\n    /// <param name=\"profile\">The profile to save.</param>\n    /// <param name=\"filePath\">The path of the file.</param>\n    /// <returns><c>true</c> if the file was correctly saved, <c>false</c> otherwise.</returns>\n    public bool SaveSettingsProfile(SettingsProfile profile, UFile filePath)\n    {\n#if NET6_0_OR_GREATER\n        ArgumentNullException.ThrowIfNull(profile);\n#else\n        if (profile is null) throw new ArgumentNullException(nameof(profile));","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Settings/SettingsContainer.cs#L189-L225","documentation":"UnloadSettingsProfile refuses to unload the profile that is currently active (CurrentProfile) with InvalidOperationException, since removing the active profile would leave SettingsKey reads without a valid resolution target. This is a state check that runs after the root-profile check.","triggerScenarios":"Calling UnloadSettingsProfile(profile) while profile == container.CurrentProfile, e.g. trying to dispose the settings profile that the application is actively using.","commonSituations":"Shutdown/teardown code unloading profiles in arbitrary order; switching between build configs where the loaded override file is also the current profile; calling unload immediately after CreateSettingsProfile(setAsCurrent: true).","solutions":["Set CurrentProfile to another profile (e.g. the RootProfile) before unloading","Do not unload the current profile; keep it until shutdown","If the intent is to replace a loaded file profile, load the replacement first, then unload the old one"],"exampleFix":"// before\ncontainer.UnloadSettingsProfile(container.CurrentProfile);\n// after\ncontainer.CurrentProfile = container.RootProfile;\ncontainer.UnloadSettingsProfile(oldProfile);","handlingStrategy":"validation","validationCode":"if (profile == container.CurrentProfile)\n    container.CurrentProfile = container.RootProfile;\ncontainer.UnloadSettingsProfile(profile);","typeGuard":null,"tryCatchPattern":"try { container.UnloadSettingsProfile(profile); }\ncatch (InvalidOperationException) { /* still current: switch profile first */ }","preventionTips":["Reset CurrentProfile to RootProfile before teardown","Unload profiles in reverse activation order","Do not unload the profile your code is actively reading settings from"],"tags":["settings","invalid-state","lifecycle"],"backgroundTag":"invalid-state-transition","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"}