dotnet/wpf · error · NotSupportedException
SR.NotSupportedOnDirective
Error message
SR.NotSupportedOnDirective
What it means
DirectiveMemberInvoker (used for XAML directives like x:Name, x:Key) overrides GetValue to always throw NotSupportedException with SR.NotSupportedOnDirective. Directives are language constructs, not CLR properties, so there is no backing value to read through the invoker.
Solutions
- Skip directives when enumerating: filter members where `member is XamlDirective` before calling GetValue.
- Handle directive semantics explicitly (e.g. read x:Name from the actual NameScope/name mechanism) instead of through the invoker.
- Catch NotSupportedException around GetValue if the member set is not known in advance.
Example fix
// before
foreach (var m in type.GetAllMembers()) Read(m); // throws on x:Name etc.
// after
foreach (var m in type.GetAllMembers())
{
if (m is XamlDirective) continue;
Read(m);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (member is XamlDirective) return; // no value to read
Type guard
static bool IsDirective(XamlMember m) => m is XamlDirective;
Try / catch
try { v = invoker.GetValue(instance); }
catch (NotSupportedException) { /* directive: no CLR value */ } Prevention
- Filter out XamlDirective instances when enumerating GetAllMembers()
- Implement explicit handling for directives you care about (x:Name, x:Key)
- Remember directives have no CLR backing property
When it happens
Trigger: Calling GetValue on the invoker of a XamlDirective (any member obtained from XamlLanguage.Name, XamlLanguage.Key, XamlLanguage.Class, etc.).
Common situations: Generic member-enumeration code that iterates type.GetAllMembers() (which includes directives) and tries to read each value; serializers dumping object graphs that encounter directive members.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- SR.CantGetWriteonlyProperty
- SR.CantSetReadonlyProperty
- SR.NotSupportedOnUnknownMember
- SR.OnlySupportedOnCollections
- CollectionIsFixedSize
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/9f479f0a28b324bd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Schema/XamlMemberInvoker.cs:167
private bool IsUnknown
{
get { return _member is null || _member.UnderlyingMember is null; }
}
private void ThrowIfUnknown()
{
if (IsUnknown)
{
throw new NotSupportedException(SR.NotSupportedOnUnknownMember);
}
}
private class DirectiveMemberInvoker : XamlMemberInvoker
{
public override object GetValue(object instance)
{
throw new NotSupportedException(SR.NotSupportedOnDirective);
}
public override void SetValue(object instance, object value)
{
throw new NotSupportedException(SR.NotSupportedOnDirective);
}
}
}
public enum ShouldSerializeResult
{
Default,
True,
False
}
}
View on GitHub (pinned to 81131a70a4)