dotnet/wpf · error · XamlSchemaException
XamlSchemaException(SR.Format(SR.UsableDuringInitializationO…
Error message
XamlSchemaException(SR.Format(SR.UsableDuringInitializationOnME, this))
What it means
XAML forbids markup extensions from being marked UsableDuringInitialization, because an extension must be fully constructed from its constructor/property inputs before providing its value; being usable during initialization is contradictory. When a type reports UsableDuringInitialization == true and IsMarkupExtension == true, XamlSchemaException UsableDuringInitializationOnME is thrown during the cached bit lookup.
Solutions
- Remove the [UsableDuringInitialization(true)] attribute from the markup extension class
- Set UsableDuringInitialization(false) explicitly on the type
- If the attribute comes from a base class, exclude it via attribute filtering or restructure inheritance
Example fix
// before
[UsableDuringInitialization(true)]
public class MyExtension : MarkupExtension { ... }
// after
public class MyExtension : MarkupExtension { ... } // attribute removed Defensive patterns
Strategy: validation
Validate before calling
bool bad = typeof(MyExtension).IsDefined(typeof(UsableDuringInitializationAttribute), false)
&& typeof(System.Xaml.Markup.MarkupExtension).IsAssignableFrom(typeof(MyExtension)); Try / catch
try { var bit = xamlType.UsableDuringInitialization; }
catch (XamlSchemaException ex) { /* remove offending attribute from the extension */ } Prevention
- Never apply UsableDuringInitialization(true) to MarkupExtension-derived classes
- Audit attribute copying when porting WPF classes to System.Xaml
- Run XAML type resolution tests over all custom markup extensions
When it happens
Trigger: Applying [UsableDuringInitialization(true)] to a class deriving from MarkupExtension, or LookupUsableDuringInitialization discovering such an attribute while resolving the type's boolean bits during XAML parsing or type lookup.
Common situations: Custom markup extensions that copy attribute sets from regular objects; WPF-era attributes carried over when porting a class to System.Xaml; reflection-based metadata incorrectly reporting the attribute.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- XamlSchemaException(SR.Format(SR.MarkupExtensionWithDuplicat…
- SR.ConverterMustDeriveFromBase
- SR.NoAddMethodFound
- ' '.' ' is a property without a getter and is not a valid…
- ' '.' ' is a property without a getter and is not a valid…
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cafe38ed6cecb8d9.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/XamlType.cs:1764
case BoolTypeBits.NameScope:
bit = LookupIsNameScope();
break;
case BoolTypeBits.Public:
bit = LookupIsPublic();
break;
case BoolTypeBits.TrimSurroundingWhitespace:
bit = LookupTrimSurroundingWhitespace();
break;
case BoolTypeBits.UsableDuringInitialization:
bit = LookupUsableDuringInitialization();
if (bit && IsMarkupExtension)
{
// MarkupExtension cannot be used during initialization.
string err = SR.Format(SR.UsableDuringInitializationOnME, this);
throw new XamlSchemaException(err);
}
break;
case BoolTypeBits.WhitespaceSignificantCollection:
bit = LookupIsWhitespaceSignificantCollection();
break;
case BoolTypeBits.XmlData:
bit = LookupIsXData();
break;
case BoolTypeBits.Ambient:
bit = LookupIsAmbient();
break;
default:
Debug.Fail("Enum out of range");View on GitHub (pinned to 81131a70a4)