fullstackhero/dotnet-starter-kit · error · InvalidOperationException
Only named Channels can be renamed.
Error message
Only named Channels can be renamed.
What it means
ChatChannel.Rename only applies to channels whose Type is ChannelType.Channel (named channels). Calling it on a DM or group DM throws InvalidOperationException because DMs have no user-visible name/slug to change.
Solutions
- Guard before calling: only show/allow rename when channel.Type == ChannelType.Channel.
- Disable the rename action in the UI for DMs and group DMs.
- For group DMs, model a display label at the client level instead of renaming the entity.
- In server code, check the channel type and return 400/409 rather than letting the domain throw.
Example fix
// before
channel.Rename(newName, newDescription);
// after
if (channel.Type != ChannelType.Channel)
return Results.BadRequest("Only named channels can be renamed.");
channel.Rename(newName, newDescription); Defensive patterns
Strategy: validation
Validate before calling
// before calling Rename
if (channel.Type != ChannelType.Channel)
throw new ValidationException("Only named channels can be renamed");
if (string.IsNullOrWhiteSpace(newName))
throw new ValidationException("Name is required"); Type guard
bool CanRename(ChatChannel c) => c.Type == ChannelType.Channel;
Try / catch
try { channel.Rename(name, description); }
catch (InvalidOperationException ex) when (ex.Message.Contains("renamed")) { return Results.Conflict(ex.Message); } Prevention
- Gate the rename UI on channel.Type == ChannelType.Channel.
- Never bulk-rename channels without filtering by type.
- Represent DM/group labels client-side instead of renaming the entity.
- Add an architecture/unit test asserting Rename throws for DM types.
When it happens
Trigger: channel.Rename(name, description) invoked on a channel created via CreateDirect or CreateGroupDm (Type == DirectMessage or GroupMessage).
Common situations: A generic 'edit channel' dialog wired to all channel types without filtering; bulk admin scripts renaming every channel in a workspace; UI state that loses the channel type after refresh and shows rename for DMs too.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot start a DM with yourself.
- Group DM requires at least 3 distinct members.
- All user ids must be non-empty.
- Only named Channels can change privacy.
- Direct messages have fixed membership.
AI-assisted analysis of fullstackhero/dotnet-starter-kit@3f2959e683 (2026-09-15).
Data as JSON: /api/errors/f65da91b60f5590b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Modules/Chat/Modules.Chat/Domain/ChatChannel.cs:152
CreatedAtUtc = DateTime.UtcNow,
};
foreach (var uid in userIds.Distinct(StringComparer.Ordinal))
{
var role = string.Equals(uid, creatorUserId, StringComparison.Ordinal)
? ChannelMemberRole.Admin
: ChannelMemberRole.Member;
c._members.Add(ChannelMember.Create(c.Id, uid, role));
}
c.AddDomainEvent(DomainEvent.Create((id, ts) =>
new ChannelCreatedDomainEvent(c.Id, c.Type, null, creatorUserId, id, ts)));
return c;
}
public void Rename(string name, string? description)
{
if (Type != ChannelType.Channel)
{
throw new InvalidOperationException("Only named Channels can be renamed.");
}
ArgumentException.ThrowIfNullOrWhiteSpace(name);
Name = name.Trim();
Slug = Slugify(name);
Description = description?.Trim();
UpdatedAtUtc = DateTime.UtcNow;
}
public void SetPrivate(bool isPrivate)
{
if (Type != ChannelType.Channel)
{
throw new InvalidOperationException("Only named Channels can change privacy.");
}
IsPrivate = isPrivate;
UpdatedAtUtc = DateTime.UtcNow;
}
View on GitHub (pinned to 3f2959e683)