dotnet/wpf · error · InvalidOperationException

SR.UnexpectedValueTypeForCondition

Error message

SR.UnexpectedValueTypeForCondition

What it means

Seal received a ValueLookupType it does not recognize; only Trigger, PropertyTriggerResource, DataTrigger and DataTriggerResource are valid. This is an internal invariant / unsupported enum value guard and throws InvalidOperationException.

Solutions

  1. Pass only valid ValueLookupType members (Trigger, PropertyTriggerResource, DataTrigger, DataTriggerResource).
  2. Let the style/trigger infrastructure call Seal itself rather than calling it manually.
  3. If hit via reflection against a newer/older framework version, align code with the current enum members.

Example fix

// before
condition.Seal((ValueLookupType)99);
// after
condition.Seal(ValueLookupType.Trigger);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!Enum.IsDefined(typeof(ValueLookupType), type))
    throw new ArgumentOutOfRangeException(nameof(type));

Type guard

bool IsKnownValueLookupType(ValueLookupType t) =>
    t is ValueLookupType.Trigger or ValueLookupType.PropertyTriggerResource
       or ValueLookupType.DataTrigger or ValueLookupType.DataTriggerResource;

Try / catch

try { condition.Seal(type); }
catch (InvalidOperationException ex) { /* pass a valid ValueLookupType */ }

Prevention

When it happens

Trigger: Passing an undefined or out-of-range ValueLookupType member to Condition.Seal, typically only reachable from internal style-sealing code or reflection.

Common situations: Framework-internal misuse or a custom framework subclass invoking Seal with an invented lookup type; virtually never hit by application developers.

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/e84a61d661473d39. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs:211

                        throw new InvalidOperationException(SR.Format(SR.NullPropertyIllegal, "Property"));
                    }

                    if (!_property.IsValidValue(_value))
                    {
                        throw new InvalidOperationException(SR.Format(SR.InvalidPropertyValue, _value, _property.Name));
                    }
                    break;

                case ValueLookupType.DataTrigger:
                case ValueLookupType.DataTriggerResource:
                    if (_binding == null)
                    {
                        throw new InvalidOperationException(SR.Format(SR.NullPropertyIllegal, "Binding"));
                    }
                    break;

                default:
                    throw new InvalidOperationException(SR.Format(SR.UnexpectedValueTypeForCondition, type));
            }

            // Freeze the condition value
            StyleHelper.SealIfSealable(_value);
        }


        #region ISupportInitialize Members

        void ISupportInitialize.BeginInit()
        {
        }

        void ISupportInitialize.EndInit()
        {
            // Resolve all properties here
            if (_unresolvedProperty != null)
            {

View on GitHub (pinned to 81131a70a4)