dotnet/wpf · error · ArgumentOutOfRangeException
ArgumentOutOfRangeException(name)
Error message
ArgumentOutOfRangeException(name)
What it means
The ContentUser constructor rejects a name that is null or whose Trim() is empty, throwing ArgumentOutOfRangeException for 'name'. A user identity must be a non-blank string (e.g. DOMAIN\user, an email, or 'Anyone'/'Owner' for the Internal auth type).
Solutions
- Validate/trim the user name and fail fast with a clear message before constructing ContentUser
- Resolve the identity robustly (e.g. WindowsIdentity.GetCurrent().Name) instead of Environment.UserName when it can be empty
- For publishing, use the literal "Anyone" with AuthenticationType.Internal when an explicit identity is not required
Example fix
// before
var user = new ContentUser(settings.UserName, AuthenticationType.Windows);
// after
string name = settings.UserName?.Trim();
if (string.IsNullOrEmpty(name))
name = WindowsIdentity.GetCurrent().Name;
var user = new ContentUser(name, AuthenticationType.Windows); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException("User name must be a non-empty string", nameof(name)); Type guard
static bool IsValidUserName(string name) => !string.IsNullOrWhiteSpace(name);
Try / catch
try { var user = new ContentUser(name, authType); }
catch (ArgumentOutOfRangeException ex) when (ex.ParamName == "name")
{
logger.LogError(ex, "Blank user name supplied for ContentUser");
throw new ApplicationException("A valid user name is required");
} Prevention
- Trim and validate identity strings at input boundaries (forms, config) before constructing ContentUser
- Resolve the current identity with WindowsIdentity.GetCurrent().Name when Environment.UserName may be empty (services, CI)
- For anonymous publishing use the literal "Anyone" with AuthenticationType.Internal rather than an empty name
When it happens
Trigger: Calling new ContentUser(name, authType) where name is "" or " " — e.g. an empty username from Environment.UserName on a service account context, an unset config value, or a blank email field.
Common situations: Running under a context where the user name cannot be resolved (service sessions, certain CI environments); empty settings field for the licensed user; trimming input from a form and passing it without a check.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- ArgumentOutOfRangeException(authentication)
- ArgumentOutOfRangeException(user)
- ArgumentOutOfRangeException(userActivationMode)
- SR.OnlyPassportOrWindowsAuthenticatedUsersAreAllowed
- ' ' is not a valid value for ' '.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/87bd8c1b7effff5e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/WindowsBase/System/Security/RightsManagement/User.cs:26
{
/// <summary>
/// This class represents a User for purposes of granting rights to that user, initializing secure environment for the user,
/// or enumerating rights granted to various users.
/// </summary>
public class ContentUser
{
/// <summary>
/// This constructor creates a user that will be granted a right. Or used in other related scenarios like
/// initializing secure environment for the user, or enumerating rights granted to various users.
/// </summary>
public ContentUser(string name, AuthenticationType authenticationType)
{
ArgumentNullException.ThrowIfNull(name);
if (name.Trim().Length == 0)
{
throw new ArgumentOutOfRangeException(nameof(name));
}
if ((authenticationType != AuthenticationType.Windows) &&
(authenticationType != AuthenticationType.Passport) &&
(authenticationType != AuthenticationType.WindowsPassport) &&
(authenticationType != AuthenticationType.Internal))
{
throw new ArgumentOutOfRangeException(nameof(authenticationType));
}
// We only support Anyone for the internal mode at the moment
if (authenticationType == AuthenticationType.Internal)
{
if (!CompareToAnyone(name) && !CompareToOwner(name))
{
// we only support Anyone as internal user
throw new ArgumentOutOfRangeException(nameof(name));
}View on GitHub (pinned to 81131a70a4)