{"record":{"id":"9fa2cf186340e0fd","repo":"BornToBeRoot/NETworkManager","slug":"group-oldprofile-group-not-found-for-old-profile","errorCode":null,"errorMessage":"Group '{oldProfile.Group}' not found for old profile.","messagePattern":"Group '(.+?)' not found for old profile\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Source/NETworkManager.Profiles/ProfileManager.cs","lineNumber":1300,"sourceCode":"    ///     Method to replace a profile in a group.\n    /// </summary>\n    /// <param name=\"oldProfile\">Old profile as <see cref=\"ProfileInfo\" />.</param>\n    /// <param name=\"newProfile\">New profile as <see cref=\"ProfileInfo\" />.</param>\n    /// <exception cref=\"ArgumentNullException\">Thrown when oldProfile or newProfile is null.</exception>\n    /// <exception cref=\"ArgumentException\">Thrown when profile groups are null or empty.</exception>\n    /// <exception cref=\"InvalidOperationException\">Thrown when old profile's group is not found.</exception>\n    public static void ReplaceProfile(ProfileInfo oldProfile, ProfileInfo newProfile)\n    {\n        ArgumentNullException.ThrowIfNull(oldProfile);\n        ArgumentNullException.ThrowIfNull(newProfile);\n        ArgumentException.ThrowIfNullOrWhiteSpace(oldProfile.Group, nameof(oldProfile));\n        ArgumentException.ThrowIfNullOrWhiteSpace(newProfile.Group, nameof(newProfile));\n\n        // Remove from old group\n        var oldGroup = LoadedProfileFileData.Groups.FirstOrDefault(x => x.Name.Equals(oldProfile.Group));\n\n        if (oldGroup == null)\n            throw new InvalidOperationException($\"Group '{oldProfile.Group}' not found for old profile.\");\n\n        oldGroup.Profiles.Remove(oldProfile);\n\n        // Add to new group (create if doesn't exist)\n        if (!GroupExists(newProfile.Group))\n            AddGroup(new GroupInfo(newProfile.Group));\n\n        var newGroup = LoadedProfileFileData.Groups.FirstOrDefault(x => x.Name.Equals(newProfile.Group));\n\n        if (newGroup == null)\n            throw new InvalidOperationException($\"Group '{newProfile.Group}' not found for new profile after creation attempt.\");\n\n        newGroup.Profiles.Add(newProfile);\n\n        ProfilesUpdated();\n    }\n\n    /// <summary>","sourceCodeStart":1282,"sourceCodeEnd":1318,"githubUrl":"https://github.com/BornToBeRoot/NETworkManager/blob/2780d65469917a296dbc15f206107d72e2d0115c/Source/NETworkManager.Profiles/ProfileManager.cs#L1282-L1318","documentation":"ReplaceProfile first removes oldProfile from its current group; the lookup of oldProfile.Group in LoadedProfileFileData.Groups returned null, so the old profile is not actually present in any known group. ReplaceProfile throws rather than leaving the profile file in a half-updated state (old profile neither removed nor new one added). This is a sentinel consistency check against stale or foreign ProfileInfo objects.","triggerScenarios":"Thrown at Source/NETworkManager.Profiles/ProfileManager.cs:1300 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the ProfileInfo instance obtained from the loaded profile data, not a detached/stale copy.","Confirm the old profile's Group matches an existing group name exactly (case/whitespace).","Use GetGroupByName or GroupExists to verify the group before calling ReplaceProfile.","If the profile was already moved or removed, skip ReplaceProfile or add the new profile directly instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2780d65469917a296dbc15f206107d72e2d0115c","analyzedAt":"2026-09-12T17:00:17.986Z","contentChangedAt":"2026-09-12T17:00:17.986Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}