{"record":{"id":"d81d399de479fd9d","repo":"icsharpcode/ILSpy","slug":"definitions-contains-null-element","errorCode":null,"errorMessage":"definitions contains null element","messagePattern":"definitions contains null element","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":1375,"sourceCode":"\t\t/// </summary>\r\n\t\tpublic SyntaxTree Decompile(params EntityHandle[] definitions)\r\n\t\t{\r\n\t\t\treturn Decompile((IEnumerable<EntityHandle>)definitions);\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Decompile the specified types and/or members.\r\n\t\t/// </summary>\r\n\t\tpublic SyntaxTree Decompile(IEnumerable<EntityHandle> definitions)\r\n\t\t{\r\n\t\t\tif (definitions == null)\r\n\t\t\t\tthrow new ArgumentNullException(nameof(definitions));\r\n\t\t\tsyntaxTree = new SyntaxTree();\r\n\t\t\tvar namespaces = new HashSet<string>();\r\n\t\t\tforeach (var entity in definitions)\r\n\t\t\t{\r\n\t\t\t\tif (entity.IsNil)\r\n\t\t\t\t\tthrow new ArgumentException(\"definitions contains null element\");\r\n\t\t\t\tRequiredNamespaceCollector.CollectNamespaces(entity, module, namespaces);\r\n\t\t\t}\r\n\t\t\tvar decompileRun = CreateDecompileRun(namespaces);\r\n\r\n\t\t\tbool first = true;\r\n\t\t\tITypeDefinition? parentTypeDef = null;\r\n\t\t\tforeach (var entity in definitions)\r\n\t\t\t{\r\n\t\t\t\tswitch (entity.Kind)\r\n\t\t\t\t{\r\n\t\t\t\t\tcase HandleKind.TypeDefinition:\r\n\t\t\t\t\t\tITypeDefinition typeDef = module.GetDefinition((TypeDefinitionHandle)entity);\r\n\t\t\t\t\t\tsyntaxTree.Members.Add(DoDecompile(typeDef, decompileRun, new SimpleTypeResolveContext(typeDef)));\r\n\t\t\t\t\t\tif (first)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tparentTypeDef = typeDef.DeclaringTypeDefinition;\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\telse if (parentTypeDef != null)\r","sourceCodeStart":1357,"sourceCodeEnd":1393,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L1357-L1393","documentation":"ArgumentException from Decompile(IEnumerable<EntityHandle>) when the sequence contains a handle with IsNil == true (default(EntityHandle), token 0). Same guard as DecompileTypes but for the mixed entity (type/method/field/property/event) overload.","triggerScenarios":"A mixed EntityHandle collection built from multiple sources where one element is default(EntityHandle); merging handles without filtering the nil sentinel.","commonSituations":"Concatenating type + member handle lists where one lookup returned default; reading handles from an array with an empty slot.","solutions":["Filter nil handles before the call: definitions.Where(h => !h.IsNil).","Validate: if (definitions.Any(h => h.IsNil)) throw ... with caller context."],"exampleFix":"// before\nvar tree = decompiler.Decompile(handles);\n\n// after\nvar valid = handles.Where(h => !h.IsNil).ToArray();\nvar tree = decompiler.Decompile(valid);","handlingStrategy":"validation","validationCode":"var valid = definitions.Where(h => !h.IsNil).ToArray();\nvar tree = decompiler.Decompile(valid);","typeGuard":"static bool IsValidEntityHandle(EntityHandle h) => !h.IsNil;","tryCatchPattern":null,"preventionTips":["Filter nil handles whenever you merge handle lists from several sources.","Treat token 0 as a sentinel, never as a real entity."],"tags":["decompilation","validation","metadata","argument"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}