dotnet/wpf · error
SR.Format(SR.ParserBamlEvent, eventName)
Error message
SR.Format(SR.ParserBamlEvent, eventName)
What it means
Like WriteRoutedEvent, WriteEvent throws NotSupportedException(SR.Format(SR.ParserBamlEvent, eventName)) when the build excludes CLR-event BAML record support. The writer cannot encode ordinary CLR events into BAML in that configuration, so the call is refused at runtime.
Solutions
- Rebuild/use PresentationFramework with the CLR-event BAML record support enabled.
- Remove or transform CLR event attributes in the source XAML before BAML serialization.
- Handle the NotSupportedException and serialize such documents as XAML text instead.
Example fix
// before
writer.WriteEvent("MouseDown", "Handler");
// after
// attach the handler in code instead of BAML:
element.MouseDown += Handler; Defensive patterns
Strategy: fallback
Validate before calling
// Pre-scan XAML for CLR event attributes (AttributeSyntax="Handler") before BAML serialization: bool hasClrEvents = xamlNodes.Any(n => n.Members.Any(m => m.IsEvent));
Try / catch
try { writer.WriteEvent(eventName, handlerName); }
catch (NotSupportedException ex) when (ex.Message.Contains("event"))
{
// fall back to XAML text output or skip the event record
} Prevention
- Verify build configuration enables CLR-event BAML records.
- Remove event attributes from XAML before BAML serialization.
- Wire event handlers in code-behind instead of markup.
When it happens
Trigger: Calling WriteEvent on a build with the CLR-event BAML record path compiled out; serializing XAML that contains CLR event attributes (e.g. MouseDown="Handler" on a non-routed event) through BamlWriter in that build.
Common situations: Custom BAML serialization pipelines in stripped WPF builds encountering event attributes; migration of serializers across build flavors with different #if settings.
Related errors
- SR.Format(SR.ParserBamlEvent, eventIdName)
- By default, ToolTip property does not support ToolTip…
- Can't Assign to Known Type attributes
- Cannot convert from type.
- Cannot convert to type.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/4480f9075df0909b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlWriter.cs:930
/// is included here for completeness and future expandability.
/// </remarks>
public void WriteEvent(
string eventName,
string handlerName)
{
#if EVENTSUPPORT
VerifyWriteState();
XamlClrEventNode eventNode = new XamlClrEventNode(
0,
0,
_depth,
eventName,
null,
handlerName);
_bamlRecordWriter.WriteClrEvent(eventNode);
#else
throw new NotSupportedException(SR.Format(SR.ParserBamlEvent, eventName));
#endif
}
#endregion Record Writing
#region Internal Methods
/***************************************************************************\
*
* BamlWriter.ProcessMarkupExtensionNodes
*
* Write out baml records for all the xamlnodes contained in the buffered
* markup extension list.
* NOTE: This list must contain only xamlnodes that are known to be part of
* MarkupExtensions. This is NOT a general method to handle all types
* of xaml nodes.
*
\***************************************************************************/View on GitHub (pinned to 81131a70a4)