{"record":{"id":"491abec4f2330c05","repo":"stride3d/stride","slug":"the-default-profile-cannot-be-unloaded","errorCode":null,"errorMessage":"The default profile cannot be unloaded","messagePattern":"The default profile cannot be unloaded","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Design/Settings/SettingsContainer.cs","lineNumber":205,"sourceCode":"            SettingsYamlSerializer.Default.Deserialize(stream, settingsFile);\n        }\n        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);","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Design/Settings/SettingsContainer.cs#L187-L223","documentation":"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.","triggerScenarios":"Calling container.UnloadSettingsProfile(container.RootProfile), typically by holding a reference obtained from CreateSettingsProfile's default parent chain or from the RootProfile property itself.","commonSituations":"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.","solutions":["Skip the RootProfile in any unload loop (compare with container.RootProfile)","Only unload profiles returned from CreateSettingsProfile/LoadSettingsProfile with registerInContainer: true","Guard the call: if (profile != container.RootProfile) container.UnloadSettingsProfile(profile);"],"exampleFix":"// before\nforeach (var p in allProfiles) container.UnloadSettingsProfile(p);\n// after\nforeach (var p in allProfiles.Where(p => p != container.RootProfile)) container.UnloadSettingsProfile(p);","handlingStrategy":"validation","validationCode":"if (profile == container.RootProfile) return; // nothing to unload","typeGuard":null,"tryCatchPattern":"try { container.UnloadSettingsProfile(profile); }\ncatch (ArgumentException) { /* profile is the root: ignore */ }","preventionTips":["Exclude RootProfile from unload loops","Track which profiles you created/loaded so you only unload those","Never assume every profile reference is unloadable"],"tags":["settings","argument-exception","lifecycle"],"backgroundTag":"invalid-argument-value","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"}