dotnet/wpf · error · ArgumentException

SR.Format(SR.InputScope_InvalidInputScopeName, "value")

Error message

SR.Format(SR.InputScope_InvalidInputScopeName, "value")

What it means

The NameValue property setter of InputScopeName validates the value against IsValidInputScopeNameValue and throws ArgumentException when it is not a recognized InputScopeNameValue. The library only accepts defined, supported input scope name values.

Solutions

  1. Assign only valid InputScopeNameValue enum members (e.g. InputScopeNameValue.Number, .EmailUserName)
  2. Validate the value with Enum.IsDefined(typeof(InputScopeNameValue), v) before assigning
  3. Fix whatever serialization produced the out-of-range numeric value

Example fix

// before
scopeName.NameValue = (InputScopeNameValue)9999;
// after
if (Enum.IsDefined(typeof(InputScopeNameValue), 9999))
    scopeName.NameValue = (InputScopeNameValue)9999;
else
    scopeName.NameValue = InputScopeNameValue.Default;
Defensive patterns

Strategy: validation

Validate before calling

bool isValid = value is InputScopeNameValue v && Enum.IsDefined(typeof(InputScopeNameValue), v);

Type guard

bool IsValidScopeName(object v) => v is InputScopeNameValue e && Enum.IsDefined(typeof(InputScopeNameValue), e);

Try / catch

try { name.NameValue = v; } catch (ArgumentException ex) { /* fallback to InputScopeNameValue.Default */ }

Prevention

When it happens

Trigger: Setting InputScopeName.NameValue to an arbitrary int cast or an undefined InputScopeNameValue enum member, e.g. new InputScopeName { NameValue = (InputScopeNameValue)9999 }.

Common situations: Casting raw integers from persisted config into InputScopeNameValue; typing errors when using enum values; data binding a string/int directly to NameValue.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/dc40c8d4e4c7fee5. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/InputScope.cs:171

            // throw new System.NotImplementedException();
        }

#endregion IAddChild

#endregion Public Methods

#region class public properties
        ///<summary>
        /// Name property - this is used when accessing the string that is set to InputScopePhrase
        ///</summary>
        public InputScopeNameValue NameValue
        {
            get { return _nameValue; }
            set 
            { 
                if (!IsValidInputScopeNameValue(value))
                {
                    throw new ArgumentException(SR.Format(SR.InputScope_InvalidInputScopeName, "value"));
                }
                _nameValue = value; 
            }
        }

#endregion class public properties

        ///<summary>
        /// This validates the value for InputScopeName.
        ///</summary>
        private bool IsValidInputScopeNameValue(InputScopeNameValue name)
        {
            switch (name)
            {
                case InputScopeNameValue.Default                   : break; // = 0,  // IS_DEFAULT
                case InputScopeNameValue.Url                       : break; // = 1,  // IS_URL
                case InputScopeNameValue.FullFilePath              : break; // = 2,  // IS_FILE_FULLFILEPATH
                case InputScopeNameValue.FileName                  : break; // = 3,  // IS_FILE_FILENAME

View on GitHub (pinned to 81131a70a4)