icsharpcode/ILSpy · error · ArgumentException
Cannot use an uncached type system in the decompiler.
Error message
Cannot use an uncached type system in the decompiler.
What it means
Thrown by the CSharpDecompiler constructor when module.TypeSystemOptions has the Uncached flag. The decompiler makes many repeated metadata lookups and requires a cached type system; an uncached one would be correct but unusably slow and is rejected with ArgumentException.
Source
Thrown at ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs:380
/// <summary>
/// Creates a new <see cref="CSharpDecompiler"/> instance from the given <paramref name="module"/> using the given <paramref name="assemblyResolver"/> and <paramref name="settings"/>.
/// </summary>
public CSharpDecompiler(MetadataFile module, IAssemblyResolver assemblyResolver, DecompilerSettings settings)
: this(new DecompilerTypeSystem(module, assemblyResolver, settings), settings)
{
}
/// <summary>
/// Creates a new <see cref="CSharpDecompiler"/> instance from the given <paramref name="typeSystem"/> and the given <paramref name="settings"/>.
/// </summary>
public CSharpDecompiler(IDecompilerTypeSystem typeSystem, DecompilerSettings settings)
{
this.typeSystem = typeSystem ?? throw new ArgumentNullException(nameof(typeSystem));
this.settings = settings;
this.module = typeSystem.MainModule;
this.metadata = module.MetadataFile.Metadata;
if (module.TypeSystemOptions.HasFlag(TypeSystemOptions.Uncached))
throw new ArgumentException("Cannot use an uncached type system in the decompiler.");
}
#region MemberIsHidden
/// <summary>
/// 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.
/// </summary>
/// <param name="module">The module containing the member.</param>
/// <param name="member">The metadata token/handle of the member. Can be a TypeDef, MethodDef or FieldDef.</param>
/// <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>
public static bool MemberIsHidden(MetadataFile? module, EntityHandle member, DecompilerSettings settings)
{
if (module == null || member.IsNil)
return false;
var metadata = module.Metadata;
string name;
switch (member.Kind)
{
case HandleKind.MethodDefinition:
View on GitHub (pinned to 60c08fcb74)
Solutions
- Do not set TypeSystemOptions.Uncached for modules you intend to decompile.
- Build the type system from a cached MetadataFile (default load path).
- Use the CSharpDecompiler(MetadataFile, IAssemblyResolver, DecompilerSettings) overload which constructs a cached DecompilerTypeSystem internally.
Example fix
// before: module loaded uncached var ts = new DecompilerTypeSystem(uncachedModule, resolver, settings); var decompiler = new CSharpDecompiler(ts, settings); // ArgumentException // after: load the module cached (default) var module = new PEFile(path); // cached metadata by default var decompiler = new CSharpDecompiler(module, resolver, settings);
Defensive patterns
Strategy: validation
Validate before calling
if (typeSystem.MainModule.TypeSystemOptions.HasFlag(TypeSystemOptions.Uncached))
throw new ArgumentException("Use a cached type system for decompilation.");
var decompiler = new CSharpDecompiler(typeSystem, settings); Try / catch
try {
var decompiler = new CSharpDecompiler(typeSystem, settings);
} catch (ArgumentException ex) when (ex.Message.Contains("uncached")) {
// rebuild the type system from a cached module and retry
} Prevention
- Keep decompilation and streaming/uncached metadata loading on separate module instances.
- Default to cached PEFile/MetadataFile for anything handed to the decompiler.
When it happens
Trigger: Passing an IDecompilerTypeSystem built from a MetadataFile loaded with TypeSystemOptions.Uncached (e.g. via UniversalAssemblyReader / an uncached assembly), or constructing the DecompilerTypeSystem on top of a metadata file opened with the uncached option.
Common situations: Caller reused an uncached reader for performance in another tool and passed the same module to the decompiler; loading assemblies with the streaming/uncached option then decompiling.
Related errors
AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13).
Data as JSON: /api/errors/6112e93c769eb8e4.
Report an issue: GitHub.