{"record":{"id":"52b236423379cb08","repo":"dotnet/wpf","slug":"sr-parserbamlevent-0","errorCode":null,"errorMessage":"SR.ParserBamlEvent: {0}","messagePattern":"SR\\.ParserBamlEvent: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs","lineNumber":1793,"sourceCode":"            }\n            else\n            {\n                return builder.ToString();\n            }\n        }\n\n        /***************************************************************************\\\n        *\n        * BamlReader.ReadRoutedEventRecord\n        *\n        * Read a routed event record.  These are currently not stored in the\n        * BAML stream, but are handled by code generated by the compiler.\n        *\n        \\***************************************************************************/\n\n        private void ReadRoutedEventRecord()\n        {\n            throw new InvalidOperationException(SR.Format(SR.ParserBamlEvent, string.Empty));\n        }\n\n        /***************************************************************************\\\n        *\n        * BamlReader.ReadClrEventRecord\n        *\n        * Read a clr event record.  These are currently not stored in the\n        * BAML stream, but are handled by code generated by the compiler.\n        *\n        \\***************************************************************************/\n\n        private void ReadClrEventRecord()\n        {\n            throw new InvalidOperationException(SR.Format(SR.ParserBamlEvent, string.Empty));\n        }\n\n        /***************************************************************************\\\n        *","sourceCodeStart":1775,"sourceCodeEnd":1811,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs#L1775-L1811","documentation":"BamlReader.ReadRoutedEventRecord unconditionally throws InvalidOperationException with SR.ParserBamlEvent. In the WPF runtime BAML reader, routed-event records are expected to be compiled away by the markup compiler (hooked up in generated code), so a RoutedEvent record in a BAML stream is an error condition at parse time.","triggerScenarios":"Parsing a BAML stream that contains a BamlRoutedEventRecord — reached via ReadRoutedEventRecord during node iteration of a markup-extension-style read.","commonSituations":"Manually produced or tool-generated BAML that still carries event hookup records; using internal BAML reading APIs on streams not produced by the standard WPF markup compiler.","solutions":["Regenerate the BAML with the standard WPF markup compiler (build the project normally) so event records are handled by generated code.","Do not rely on the runtime BamlReader for streams containing event hookups; use XamlReader/load-path APIs instead.","Remove or replace event attribute hookups with code-behind wiring if generating BAML with custom tooling."],"exampleFix":"// before: XAML with event attribute compiled by non-standard tool\n<Button Click=\"OnClick\" />\n\n// after: wire in code-behind\n<Button x:Name=\"btn\" />\n// in constructor:\nbtn.Click += OnClick;","handlingStrategy":"validation","validationCode":"// reject streams containing routed-event records before reading\n// (walk records with the map table, or simply rebuild with the standard compiler)\nif (bamlRecords.Any(r => r.RecordType == BamlRecordType.RoutedEvent))\n    throw new NotSupportedException(\"BAML contains routed-event records; rebuild with the WPF markup compiler.\");","typeGuard":"bool HasEventRecords(IEnumerable<BamlRecord> recs) => recs.Any(r => r.RecordType == BamlRecordType.RoutedEvent || r.RecordType == BamlRecordType.ClrEvent);","tryCatchPattern":"try { reader.Read(); }\ncatch (InvalidOperationException) {\n    log.LogError(\"BAML stream contains event records; use the standard markup compiler or XamlReader.Load instead.\");\n}","preventionTips":["Compile XAML with the standard WPF markup compiler (do not hand-roll BAML).","Wire events in code-behind when generating markup programmatically.","Use XamlReader.Load for dynamic XAML that includes event attributes."],"tags":["wpf","baml","routed-events","unsupported-operation"],"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"}