{"record":{"id":"ecf11c59a7e8dc15","repo":"icsharpcode/ILSpy","slug":"typesystem","errorCode":null,"errorMessage":"typeSystem","messagePattern":"typeSystem","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs","lineNumber":375,"sourceCode":"\t\tpublic CSharpDecompiler(string fileName, IAssemblyResolver assemblyResolver, DecompilerSettings settings)\r\n\t\t\t: this(LoadPEFile(fileName, settings), assemblyResolver, settings)\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Creates a new <see cref=\"CSharpDecompiler\"/> instance from the given <paramref name=\"module\"/> using the given <paramref name=\"assemblyResolver\"/> and <paramref name=\"settings\"/>.\r\n\t\t/// </summary>\r\n\t\tpublic CSharpDecompiler(MetadataFile module, IAssemblyResolver assemblyResolver, DecompilerSettings settings)\r\n\t\t\t: this(new DecompilerTypeSystem(module, assemblyResolver, settings), settings)\r\n\t\t{\r\n\t\t}\r\n\r\n\t\t/// <summary>\r\n\t\t/// Creates a new <see cref=\"CSharpDecompiler\"/> instance from the given <paramref name=\"typeSystem\"/> and the given <paramref name=\"settings\"/>.\r\n\t\t/// </summary>\r\n\t\tpublic CSharpDecompiler(IDecompilerTypeSystem typeSystem, DecompilerSettings settings)\r\n\t\t{\r\n\t\t\tthis.typeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem));\r\n\t\t\tthis.settings = settings;\r\n\t\t\tthis.module = typeSystem.MainModule;\r\n\t\t\tthis.metadata = module.MetadataFile.Metadata;\r\n\t\t\tif (module.TypeSystemOptions.HasFlag(TypeSystemOptions.Uncached))\r\n\t\t\t\tthrow new ArgumentException(\"Cannot use an uncached type system in the decompiler.\");\r\n\t\t}\r\n\r\n\t\t#region MemberIsHidden\r\n\t\t/// <summary>\r\n\t\t/// Determines whether a <paramref name=\"member\"/> should be hidden from the decompiled code. This is used to exclude compiler-generated code that is handled by transforms from the output.\r\n\t\t/// </summary>\r\n\t\t/// <param name=\"module\">The module containing the member.</param>\r\n\t\t/// <param name=\"member\">The metadata token/handle of the member. Can be a TypeDef, MethodDef or FieldDef.</param>\r\n\t\t/// <param name=\"settings\">The settings used to determine whether code should be hidden. E.g. if async methods are not transformed, async state machines are included in the decompiled code.</param>\r\n\t\tpublic static bool MemberIsHidden(MetadataFile? module, EntityHandle member, DecompilerSettings settings)\r\n\t\t{\r\n\t\t\tif (module == null || member.IsNil)\r\n\t\t\t\treturn false;\r","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs#L357-L393","documentation":"Thrown by the CSharpDecompiler(IDecompilerTypeSystem, DecompilerSettings) constructor: this.typeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem)). The message is the parameter name 'typeSystem'. The decompiler needs a fully built type system to operate.","triggerScenarios":"Constructing new CSharpDecompiler(null, settings), or a caller whose factory returned a null type system.","commonSituations":"Caller forgot to build a DecompilerTypeSystem; a DI/MEF composition that failed to provide the type system.","solutions":["Build an IDecompilerTypeSystem first (e.g. new DecompilerTypeSystem(module, resolver, settings)) and pass it.","Or use the CSharpDecompiler(MetadataFile, IAssemblyResolver, DecompilerSettings) overload, which builds the type system for you.","Null-check the type system before constructing."],"exampleFix":"// before\nvar decompiler = new CSharpDecompiler(null, settings);\n\n// after\nvar ts = new DecompilerTypeSystem(module, resolver, settings);\nvar decompiler = new CSharpDecompiler(ts, settings);\n// or simply:\n// var decompiler = new CSharpDecompiler(module, resolver, settings);","handlingStrategy":"validation","validationCode":"if (typeSystem == null) throw new ArgumentNullException(nameof(typeSystem));\nvar decompiler = new CSharpDecompiler(typeSystem, settings);","typeGuard":null,"tryCatchPattern":"var decompiler = typeSystem != null\n    ? new CSharpDecompiler(typeSystem, settings)\n    : throw new ArgumentNullException(nameof(typeSystem));","preventionTips":["Prefer the (MetadataFile, IAssemblyResolver, DecompilerSettings) overload to avoid constructing a null type system."],"tags":["decompiler","csharp","argument-null"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}