dotnet/wpf · error · InvalidOperationException

SR.ParserMapPIMissingAssembly

Error message

SR.ParserMapPIMissingAssembly

What it means

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.

Solutions

  1. Rebuild the project to regenerate a well-formed BAML stream with assembly info records preceding PI mapping records.
  2. If writing custom BAML tooling, emit BamlAssemblyInfoRecord for every assembly before any BamlPIMappingRecord that references it.
  3. Verify the deployed assembly's resources are intact (no partial copy) and re-deploy if needed.
Defensive patterns

Strategy: validation

Validate before calling

// ensure every PI mapping's assembly id has a known assembly info record
foreach (var pi in records.OfType<BamlPIMappingRecord>())
    if (mapTable.GetAssemblyInfoFromId(pi.AssemblyId) == null)
        throw new InvalidOperationException($"PI mapping references unknown assembly id {pi.AssemblyId}.");

Type guard

bool PiMappingsResolvable(IEnumerable<BamlRecord> recs) =>
    recs.OfType<BamlPIMappingRecord>().All(pi =>
        recs.OfType<BamlAssemblyInfoRecord>().Any(a => a.AssemblyId == pi.AssemblyId));

Try / catch

try { reader.Read(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("assembly")) {
    log.LogError("BAML PI mapping references an unknown assembly — assembly info record missing from stream.");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/7e4029e0d09898c9. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs:1889

        /***************************************************************************\
        *
        * BamlReader.ReadPIMappingRecord
        *
        * Read the clr to xml namespace to assembly mapping record.  The contents
        * of this record are represented as three properties, one each for
        * XmlNamespace, ClrNamespace and Assembly Name.
        *
        \***************************************************************************/

        private void ReadPIMappingRecord()
        {
            BamlPIMappingRecord piMappingRecord = (BamlPIMappingRecord)_currentBamlRecord;
            BamlAssemblyInfoRecord assemblyInfo = MapTable.GetAssemblyInfoFromId(
                                                                  piMappingRecord.AssemblyId);
            if (assemblyInfo == null)
            {
                throw new InvalidOperationException(SR.ParserMapPIMissingAssembly);
            }

            // If this mapping has not already been set up, then set it now
            if (!_parserContext.XamlTypeMapper.PITable.Contains(piMappingRecord.XmlNamespace))
            {
                // Add information to the MappingPI hashtable and the reverse lookup
                // hashtable.
                _parserContext.XamlTypeMapper.AddMappingProcessingInstruction(piMappingRecord.XmlNamespace,
                                                   piMappingRecord.ClrNamespace,
                                                   assemblyInfo.AssemblyFullName);
            }

            ClearProperties();
            NodeTypeInternal = BamlNodeType.PIMapping;
            _name = "Mapping";
            _localName = _name;
            _ownerTypeName = string.Empty;

View on GitHub (pinned to 81131a70a4)