{"record":{"id":"7e4029e0d09898c9","repo":"dotnet/wpf","slug":"sr-parsermappimissingassembly","errorCode":null,"errorMessage":"SR.ParserMapPIMissingAssembly","messagePattern":"SR\\.ParserMapPIMissingAssembly","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs","lineNumber":1889,"sourceCode":"\n        /***************************************************************************\\\n        *\n        * BamlReader.ReadPIMappingRecord\n        *\n        * Read the clr to xml namespace to assembly mapping record.  The contents\n        * of this record are represented as three properties, one each for\n        * XmlNamespace, ClrNamespace and Assembly Name.\n        *\n        \\***************************************************************************/\n\n        private void ReadPIMappingRecord()\n        {\n            BamlPIMappingRecord piMappingRecord = (BamlPIMappingRecord)_currentBamlRecord;\n            BamlAssemblyInfoRecord assemblyInfo = MapTable.GetAssemblyInfoFromId(\n                                                                  piMappingRecord.AssemblyId);\n            if (assemblyInfo == null)\n            {\n                throw new InvalidOperationException(SR.ParserMapPIMissingAssembly);\n            }\n\n            // If this mapping has not already been set up, then set it now\n            if (!_parserContext.XamlTypeMapper.PITable.Contains(piMappingRecord.XmlNamespace))\n            {\n                // Add information to the MappingPI hashtable and the reverse lookup\n                // hashtable.\n                _parserContext.XamlTypeMapper.AddMappingProcessingInstruction(piMappingRecord.XmlNamespace,\n                                                   piMappingRecord.ClrNamespace,\n                                                   assemblyInfo.AssemblyFullName);\n            }\n\n            ClearProperties();\n            NodeTypeInternal = BamlNodeType.PIMapping;\n            _name = \"Mapping\";\n            _localName = _name;\n            _ownerTypeName = string.Empty;\n","sourceCodeStart":1871,"sourceCodeEnd":1907,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs#L1871-L1907","documentation":"BamlReader.ReadPIMappingRecord throws SR.ParserMapPIMissingAssembly when a ProcessingInstruction mapping record (e.g. an XmlnsDefinition-style PI) references an assembly id that has no corresponding BamlAssemblyInfoRecord in the map table. The reader cannot resolve which assembly the namespace maps to and aborts with InvalidOperationException.","triggerScenarios":"Reading BAML whose BamlPIMappingRecord.AssemblyId does not resolve via MapTable.GetAssemblyInfoFromId — the BamlAssemblyInfoRecord for that id was never read or is missing from the stream.","commonSituations":"Truncated or reordered BAML streams (assembly records must precede PI mapping records); custom BAML writers emitting PI mappings before assembly records; corrupted resources after partial deployment.","solutions":["Rebuild the project to regenerate a well-formed BAML stream with assembly info records preceding PI mapping records.","If writing custom BAML tooling, emit BamlAssemblyInfoRecord for every assembly before any BamlPIMappingRecord that references it.","Verify the deployed assembly's resources are intact (no partial copy) and re-deploy if needed."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// ensure every PI mapping's assembly id has a known assembly info record\nforeach (var pi in records.OfType<BamlPIMappingRecord>())\n    if (mapTable.GetAssemblyInfoFromId(pi.AssemblyId) == null)\n        throw new InvalidOperationException($\"PI mapping references unknown assembly id {pi.AssemblyId}.\");","typeGuard":"bool PiMappingsResolvable(IEnumerable<BamlRecord> recs) =>\n    recs.OfType<BamlPIMappingRecord>().All(pi =>\n        recs.OfType<BamlAssemblyInfoRecord>().Any(a => a.AssemblyId == pi.AssemblyId));","tryCatchPattern":"try { reader.Read(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"assembly\")) {\n    log.LogError(\"BAML PI mapping references an unknown assembly — assembly info record missing from stream.\");\n}","preventionTips":["Emit BamlAssemblyInfoRecord entries before PI mapping records in custom BAML writers.","Rebuild XAML projects after changing referenced assemblies.","Verify resource streams survive deployment intact."],"tags":["wpf","baml","xmlns-mapping","missing-record"],"backgroundTag":"missing-dependency","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"}