{"record":{"id":"2cfe59014bbfa17d","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"removed-all-nodes","errorCode":null,"errorMessage":"Removed all nodes","messagePattern":"Removed all nodes","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignToolkit.ResourceGeneration/IconThing.cs","lineNumber":133,"sourceCode":"        var syntaxTree = CSharpSyntaxTree.ParseText(sourceText);\n\n        var mySyntaxRewriter = new IconDataFactorySyntaxRewriter(icons);\n        var node = mySyntaxRewriter.Visit(syntaxTree.GetRoot());\n\n        return node.ToString();\n    }\n\n    private static string UpdateEnum(string sourceFile, IEnumerable<Icon> icons)\n    {\n        var sourceText = SourceText.From(new FileStream(sourceFile, FileMode.Open));\n        var syntaxTree = CSharpSyntaxTree.ParseText(sourceText);\n\n        var rootNode = syntaxTree.GetRoot();\n        var namespaceDeclarationNode = rootNode.ChildNodes().Single();\n        var enumDeclarationSyntaxNode = namespaceDeclarationNode.ChildNodes().OfType<EnumDeclarationSyntax>().Single();\n\n        var emptyEnumDeclarationSyntaxNode = enumDeclarationSyntaxNode.RemoveNodes(enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>(), SyntaxRemoveOptions.KeepDirectives)\n            ?? throw new Exception(\"Removed all nodes\");\n\n        var leadingTriviaList = SyntaxTriviaList.Create(SyntaxFactory.Whitespace(\"        \"));\n        var enumMemberDeclarationSyntaxs = icons.SelectMany(GetEnumMemberDeclarations).ToArray();\n        var generatedEnumDeclarationSyntax = emptyEnumDeclarationSyntaxNode.AddMembers(enumMemberDeclarationSyntaxs);\n\n        generatedEnumDeclarationSyntax = AddLineFeedsToCommas(generatedEnumDeclarationSyntax);\n\n        var generatedNamespaceDeclarationSyntaxNode = namespaceDeclarationNode.ReplaceNode(enumDeclarationSyntaxNode, generatedEnumDeclarationSyntax);\n        var generatedRootNode = rootNode.ReplaceNode(namespaceDeclarationNode, generatedNamespaceDeclarationSyntaxNode);\n\n        return generatedRootNode.ToFullString();\n\n        IEnumerable<EnumMemberDeclarationSyntax> GetEnumMemberDeclarations(Icon icon)\n        {\n            var emptyAttributes = new SyntaxList<AttributeListSyntax>();\n            SyntaxToken iconIdentifierToken = SyntaxFactory.Identifier(leadingTriviaList, icon.Name, SyntaxTriviaList.Empty);\n\n            yield return SyntaxFactory.EnumMemberDeclaration(iconIdentifierToken);","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignToolkit.ResourceGeneration/IconThing.cs#L115-L151","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!enumDeclarationSyntaxNode.ChildNodes().OfType<EnumMemberDeclarationSyntax>().Any()\n    && !icons.Any())\n    throw new InvalidOperationException(\"Template has no enum members and no icons to add.\");","typeGuard":null,"tryCatchPattern":"try { return UpdateEnum(templatePath, icons); }\ncatch (Exception ex) when (ex.Message == \"Removed all nodes\")\n{ /* restore template from source control and re-run */ }","preventionTips":["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."],"tags":["tooling","source-generation","roslyn","pack-icon"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}