iOfficeAI/OfficeCLI · error · ArgumentException
Unknown part type: {partType}. Supported: chart, chartex, dr
Error message
Unknown part type: {partType}. Supported: chart, chartex, drawing-group, ole What it means
The switch over partType.ToLowerInvariant() in AddPart fell through to the default branch — the supplied part type is not one of the supported carriers: chart, chartex, drawing-group, ole. The message enumerates the valid values so the caller can correct the type.
Source
Thrown at src/officecli/Handlers/Excel/ExcelHandler.Add.cs:1364
var oleWsElement = GetSheet(oleWs);
var oleObjects = oleWsElement.GetFirstChild<OleObjects>();
if (oleObjects == null)
{
oleObjects = new OleObjects();
oleWsElement.AppendChild(oleObjects);
}
OpenXmlElement oleChild = oleObjectXml.Contains("AlternateContent", StringComparison.Ordinal)
? new DocumentFormat.OpenXml.AlternateContent(oleObjectXml)
: new OleObject(oleObjectXml);
oleObjects.AppendChild(oleChild);
ReorderWorksheetChildren(oleWsElement);
SaveWorksheet(oleWs);
return (oleRid, $"/{oleSheetName}/ole");
}
default:
throw new ArgumentException(
$"Unknown part type: {partType}. Supported: chart, chartex, drawing-group, ole");
}
}
private static void RemapDrawingRelationshipId(
OpenXmlElement root, string sourceId, string destinationId)
{
const string relNs =
"http://schemas.openxmlformats.org/officeDocument/2006/relationships";
foreach (var element in root.Descendants().Prepend(root))
{
foreach (var attr in element.GetAttributes()
.Where(a => a.NamespaceUri == relNs && a.Value == sourceId)
.ToList())
{
element.SetAttribute(new OpenXmlAttribute(
attr.Prefix, attr.LocalName, attr.NamespaceUri, destinationId));
}View on GitHub (pinned to 1ced45e900)
Solutions
- Use one of: chart, chartex, drawing-group, ole.
- For picture/shape/table/slicer/sparkline use the Add(...) element API, not AddPart.
- Check the type spelling and casing (matching is case-insensitive but spelling must match).
- Re-dump to see the exact partType labels the emitter uses.
Example fix
// before
handler.AddPart("/Sheet1", "smartart", props);
// after — chartEx is the xlsx extended-chart carrier
handler.AddPart("/Sheet1", "chartex", props); Defensive patterns
Strategy: validation
Validate before calling
var supported = new[]{ "chart", "chartex", "drawing-group", "ole" };
if (!supported.Contains(partType?.ToLowerInvariant()))
throw new ArgumentOutOfRangeException(nameof(partType),
$"'{partType}' is not a supported part type. Use one of: {string.Join(", ", supported)}"); Type guard
static bool IsSupportedPartType(string? t) =>
t?.ToLowerInvariant() is "chart" or "chartex" or "drawing-group" or "ole"; Try / catch
try { handler.AddPart(parent, partType, props); }
catch (ArgumentException ex) when (ex.Message.Contains("Unknown part type"))
{ /* switch to a supported carrier or to the Add element API */ } Prevention
- Use only chart/chartex/drawing-group/ole for AddPart.
- For picture/shape/table/slicer/sparkline use the Add element API, not AddPart.
- Re-dump to confirm the exact partType labels the emitter emits.
When it happens
Trigger: AddPart(parent, partType, ...) with a partType that is null (NullReferenceException aside, ToLowerInvariant would throw first), misspelled, differently cased-but-still-unknown, or a type that belongs to a different format (e.g. 'slide', 'smartart').
Common situations: Typo in the type string; passing a semantic element type (e.g. 'picture','shape') to AddPart instead of the Add path; using a pptx-specific part type on an xlsx file; stale documentation naming a removed type.
Related errors
- drawing-group hyperlink entries require non-empty Id and Tar
- Property 'sqref' (or 'range'/'ref') is required for validati
- Sheet not found: {sheetName}
- Move not supported for: {elementRef}. Supported: row[N], col
- Swap requires element paths (e.g. /Sheet1/row[1])
AI-assisted analysis of iOfficeAI/OfficeCLI@1ced45e900 (2026-08-13).
Data as JSON: /api/errors/b15ca6fdcb02dd39.
Report an issue: GitHub.