MaterialDesignInXAML/MaterialDesignInXamlToolkit · error · Exception
Removed all nodes
Error message
Removed all nodes
What it means
IconThing is a maintenance/source-generation utility in MaterialDesignToolkit.ResourceGeneration, not shipped runtime code. UpdateEnum loads PackIconKind.template.cs and uses Roslyn RemoveNodes to strip the existing enum members before re-adding them from downloaded icon data. RemoveNodes can return null when the structural removal yields no node, and the `?? throw new Exception("Removed all nodes")` guards that. The message indicates the template file is malformed/empty or its tree does not match the expected namespace>enum shape.
Source
Thrown at src/MaterialDesignToolkit.ResourceGeneration/IconThing.cs:133
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText);
var mySyntaxRewriter = new IconDataFactorySyntaxRewriter(icons);
var node = mySyntaxRewriter.Visit(syntaxTree.GetRoot());
return node.ToString();
}
private static string UpdateEnum(string sourceFile, IEnumerable<Icon> icons)
{
var sourceText = SourceText.From(new FileStream(sourceFile, FileMode.Open));
var syntaxTree = CSharpSyntaxTree.ParseText(sourceText);
var rootNode = syntaxTree.GetRoot();
var namespaceDeclarationNode = rootNode.ChildNodes().Single();
var enumDeclarationSyntaxNode = namespaceDeclarationNode.ChildNodes().OfType<EnumDeclarationSyntax>().Single();
var emptyEnumDeclarationSyntaxNode = enumDeclarationSyntaxNode.RemoveNodes(enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>(), SyntaxRemoveOptions.KeepDirectives)
?? throw new Exception("Removed all nodes");
var leadingTriviaList = SyntaxTriviaList.Create(SyntaxFactory.Whitespace(" "));
var enumMemberDeclarationSyntaxs = icons.SelectMany(GetEnumMemberDeclarations).ToArray();
var generatedEnumDeclarationSyntax = emptyEnumDeclarationSyntaxNode.AddMembers(enumMemberDeclarationSyntaxs);
generatedEnumDeclarationSyntax = AddLineFeedsToCommas(generatedEnumDeclarationSyntax);
var generatedNamespaceDeclarationSyntaxNode = namespaceDeclarationNode.ReplaceNode(enumDeclarationSyntaxNode, generatedEnumDeclarationSyntax);
var generatedRootNode = rootNode.ReplaceNode(namespaceDeclarationNode, generatedNamespaceDeclarationSyntaxNode);
return generatedRootNode.ToFullString();
IEnumerable<EnumMemberDeclarationSyntax> GetEnumMemberDeclarations(Icon icon)
{
var emptyAttributes = new SyntaxList<AttributeListSyntax>();
SyntaxToken iconIdentifierToken = SyntaxFactory.Identifier(leadingTriviaList, icon.Name, SyntaxTriviaList.Empty);
yield return SyntaxFactory.EnumMemberDeclaration(iconIdentifierToken);View on GitHub (pinned to 98edec3a0b)
Solutions
- Restore PackIconKind.template.cs to its committed state; it must contain the PackIconKind enum declaration.
- Verify the template's top node is a namespace containing an enum declaration before running the generator.
- Run the generator from the repo root so the 'PackIconKind.template.cs' relative path resolves correctly.
Defensive patterns
Strategy: try-catch
Validate before calling
if (!enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>().Any()
&& !icons.Any())
throw new InvalidOperationException("Template has no enum members and no icons to add."); Try / catch
try { return UpdateEnum(templatePath, icons); }
catch (Exception ex) when (ex.Message == "Removed all nodes")
{ /* restore template from source control and re-run */ } Prevention
- Keep PackIconKind.template.cs under source control and untouched by hand edits.
- Run the generator from the repository root so relative paths resolve.
- Pin the Microsoft.CodeAnalysis version used by the generator.
When it happens
Trigger: Running the icon-generation tool against a PackIconKind.template.cs that has no enum members, or whose syntax tree does not match the expected namespace > EnumDeclaration shape so RemoveNodes returns null.
Common situations: Editing the template by hand, switching Roslyn/Microsoft.CodeAnalysis versions, or running the generator from the wrong working directory so the relative path resolves to the wrong file.
Related errors
AI-assisted analysis of MaterialDesignInXAML/MaterialDesignInXamlToolkit@98edec3a0b (2026-08-13).
Data as JSON: /api/errors/2cfe59014bbfa17d.
Report an issue: GitHub.