dotnet/wpf · error · XamlParseException
SR.ParserTooManyAssemblies
Error message
SR.ParserTooManyAssemblies
What it means
AssemblyInfoRecord's AssemblyId property throws XamlParseException(SR.ParserTooManyAssemblies) when an assembly ID exceeds 0x0FFF (4095). The BAML format reserves the top bits of the 16-bit assembly ID for flags, so more than ~4095 distinct assembly references cannot be encoded.
Solutions
- Reduce the number of assemblies referenced from XAML (consolidate control libraries, remove unused xmlns mappings)
- Split the UI into multiple independently compiled projects to cap per-BAML assembly references
- Audit xmlns/namespace imports for accidental assembly pulls (e.g. clr-namespace mapping huge assemblies)
- If genuinely needed, this is a BAML format limit — escalate to the WPF team
Defensive patterns
Strategy: validation
Validate before calling
// track distinct assembly references during XAML compilation and fail early
if (assemblyIds.Count >= 0x0FFF)
throw new InvalidOperationException("Too many assemblies referenced from XAML (limit 4095)"); Try / catch
try { CompileBaml(project); }
catch (XamlParseException ex) when (ex.Message.Contains("assemblies")) {
log.Error("Reduce referenced assemblies in XAML below 4095"); throw;
} Prevention
- Consolidate control libraries
- Prune unused xmlns/clr-namespace imports
- Split very large XAML projects
When it happens
Trigger: Compiling BAML that references more than 4095 distinct assemblies — each unique assembly reference consumed during writing gets a sequential ID in AssemblyId.
Common situations: Huge XAML projects or merged markup referencing an enormous closure of assemblies (control libraries, plugins, generated code) hitting the 12-bit ID limit during build.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Can't Assign to Known Type attributes
- Could not find prefix for type
- Found unexpected Xmlns BAML record
- NotImplementedException
- SR.AssemblyIdNegative
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/16401873408f427e.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecords.cs:4349
set
{
_flags[_typeIdLowSection] = (short) (value & 0xff);
_flags[_typeIdHighSection] = (short) ((value & 0xff00) >> 8);
}
}
// Assembly id of the assembly where this type is defined.
// NOTE: This is always positive in BAML files, but can be set
// to -1 for known types when created programmatically.
internal short AssemblyId
{
get { return _assemblyId; }
set
{
// Make sure we don't intrude on the Flags portion of the assembly ID
if (_assemblyId > 0x0FFF)
{
throw new XamlParseException(SR.ParserTooManyAssemblies);
}
_assemblyId = value;
}
}
// Fully qualified name of type, including namespace
internal string TypeFullName
{
get { return _typeFullName; }
set { _typeFullName = value; }
}
// Additional properties not stored in the baml stream
internal override BamlRecordType RecordType
{
get { return BamlRecordType.TypeInfo; }
}View on GitHub (pinned to 81131a70a4)