{"record":{"id":"4480f9075df0909b","repo":"dotnet/wpf","slug":"sr-format-sr-parserbamlevent-eventname","errorCode":null,"errorMessage":"SR.Format(SR.ParserBamlEvent, eventName)","messagePattern":"SR\\.Format\\(SR\\.ParserBamlEvent, eventName\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlWriter.cs","lineNumber":930,"sourceCode":"        /// is included here for completeness and future expandability.\n        /// </remarks>\n        public void WriteEvent(\n            string    eventName,\n            string    handlerName)\n        {\n#if EVENTSUPPORT            \n            VerifyWriteState();\n\n            XamlClrEventNode eventNode = new XamlClrEventNode(\n                                                  0,\n                                                  0,\n                                                  _depth,\n                                                  eventName,\n                                                  null,\n                                                  handlerName);\n            _bamlRecordWriter.WriteClrEvent(eventNode);\n#else\n            throw new NotSupportedException(SR.Format(SR.ParserBamlEvent, eventName));\n#endif\n        }\n\n#endregion Record Writing\n\n#region Internal Methods\n\n    /***************************************************************************\\\n    *\n    * BamlWriter.ProcessMarkupExtensionNodes\n    *\n    * Write out baml records for all the xamlnodes contained in the buffered\n    * markup extension list.\n    * NOTE:  This list must contain only xamlnodes that are known to be part of\n    *        MarkupExtensions.  This is NOT a general method to handle all types\n    *        of xaml nodes.\n    *\n    \\***************************************************************************/","sourceCodeStart":912,"sourceCodeEnd":948,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlWriter.cs#L912-L948","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom BAML serialization pipelines in stripped WPF builds encountering event attributes; migration of serializers across build flavors with different #if settings.","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."],"exampleFix":"// before\nwriter.WriteEvent(\"MouseDown\", \"Handler\");\n// after\n// attach the handler in code instead of BAML:\nelement.MouseDown += Handler;","handlingStrategy":"fallback","validationCode":"// Pre-scan XAML for CLR event attributes (AttributeSyntax=\"Handler\") before BAML serialization:\nbool hasClrEvents = xamlNodes.Any(n => n.Members.Any(m => m.IsEvent));","typeGuard":null,"tryCatchPattern":"try { writer.WriteEvent(eventName, handlerName); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"event\"))\n{\n    // fall back to XAML text output or skip the event record\n}","preventionTips":["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."],"tags":["wpf","baml","not-supported","events"],"backgroundTag":"operation-not-supported","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}