BornToBeRoot/NETworkManager · error · InvalidOperationException
Group ' ' not found for old profile.
Error message
Group '{oldProfile.Group}' not found for old profile. What it means
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.
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.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at Source/NETworkManager.Profiles/ProfileManager.cs:1300 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BornToBeRoot/NETworkManager@2780d65469 (2026-09-12).
Data as JSON: /api/errors/9fa2cf186340e0fd.
Report an issue: GitHub.
Appendix: source
Thrown at Source/NETworkManager.Profiles/ProfileManager.cs:1300
/// Method to replace a profile in a group.
/// </summary>
/// <param name="oldProfile">Old profile as <see cref="ProfileInfo" />.</param>
/// <param name="newProfile">New profile as <see cref="ProfileInfo" />.</param>
/// <exception cref="ArgumentNullException">Thrown when oldProfile or newProfile is null.</exception>
/// <exception cref="ArgumentException">Thrown when profile groups are null or empty.</exception>
/// <exception cref="InvalidOperationException">Thrown when old profile's group is not found.</exception>
public static void ReplaceProfile(ProfileInfo oldProfile, ProfileInfo newProfile)
{
ArgumentNullException.ThrowIfNull(oldProfile);
ArgumentNullException.ThrowIfNull(newProfile);
ArgumentException.ThrowIfNullOrWhiteSpace(oldProfile.Group, nameof(oldProfile));
ArgumentException.ThrowIfNullOrWhiteSpace(newProfile.Group, nameof(newProfile));
// Remove from old group
var oldGroup = LoadedProfileFileData.Groups.FirstOrDefault(x => x.Name.Equals(oldProfile.Group));
if (oldGroup == null)
throw new InvalidOperationException($"Group '{oldProfile.Group}' not found for old profile.");
oldGroup.Profiles.Remove(oldProfile);
// Add to new group (create if doesn't exist)
if (!GroupExists(newProfile.Group))
AddGroup(new GroupInfo(newProfile.Group));
var newGroup = LoadedProfileFileData.Groups.FirstOrDefault(x => x.Name.Equals(newProfile.Group));
if (newGroup == null)
throw new InvalidOperationException($"Group '{newProfile.Group}' not found for new profile after creation attempt.");
newGroup.Profiles.Add(newProfile);
ProfilesUpdated();
}
/// <summary>View on GitHub (pinned to 2780d65469)