icsharpcode/ILSpy · error · Exception

Could not resolve known assembly '{name}'!

Error message

Could not resolve known assembly '{name}'!

What it means

Thrown by KnownThings.ResolveAssembly while initializing the well-known WPF type table. It searches typeSystem.Modules for a module whose AssemblyName equals a hard-coded 'known' assembly (e.g. PresentationCore/PresentationFramework/WindowsBase) and throws a bare Exception if none is present. BAML decompilation depends on these reference assemblies being loaded into the type system.

Source

Thrown at ICSharpCode.BamlDecompiler/Baml/KnownThings.cs:75

				InitStrings();
				InitResources();
			}
			catch (Exception ex)
			{
				throw new ICSharpCode.Decompiler.DecompilerException(typeSystem.MainModule.MetadataFile, ex.Message, ex);
			}
		}

		public Func<KnownTypes, ITypeDefinition> Types => id => types[id];
		public Func<KnownMembers, KnownMember> Members => id => members[id];
		public Func<short, string> Strings => id => strings[id];
		public Func<short, (string, string, string)> Resources => id => resources[id];
		public IModule FrameworkAssembly => assemblies[0];
		IModule ResolveAssembly(string name)
		{
			IModule module = typeSystem.Modules.FirstOrDefault(m => m.AssemblyName == name);
			if (module == null)
				throw new Exception("Could not resolve known assembly '" + name + "'!");
			return module;
		}

		ITypeDefinition InitType(IModule assembly, string ns, string name)
		{
			// A synthetic stand-in only materializes the types the BAML decompiler explicitly seeds
			// here, keeping it bounded to the well-known set. Any other lookup on it returns null.
			if (assembly is SyntheticWpfModule synthetic)
				return synthetic.RegisterType(ns, name);
			return assembly.GetTypeDefinition(new TopLevelTypeName(ns, name));
		}
		KnownMember InitMember(KnownTypes parent, string name, ITypeDefinition type) => new KnownMember(parent, types[parent], name, type);
	}

	internal class KnownMember
	{
		public KnownMember(KnownTypes parent, ITypeDefinition declType, string name, ITypeDefinition type)
		{

View on GitHub (pinned to 60c08fcb74)

Solutions

  1. Ensure the WPF reference assemblies (WindowsBase, PresentationCore, PresentationFramework, System.Xaml) are resolvable by the assembly resolver used to build the type system.
  2. Add the reference-assembly path (e.g. the framework Reference Assemblies directory) to the resolver's search locations.
  3. Build the type system with the BAML resource's parent assembly so transitive references are loaded.

Example fix

// before: resolver only knows the host assembly
var ts = new DecompilerTypeSystem(module, minimalResolver, settings);
var known = new KnownThings(ts); // may throw 'Could not resolve known assembly ...'

// after: resolver also finds WPF reference assemblies
var resolver = new UniversalAssemblyResolver(targetFramework, true, null);
resolver.AddSearchDirectory(wpfReferenceAssembliesPath);
var ts = new DecompilerTypeSystem(module, resolver, settings);
var known = new KnownThings(ts);
Defensive patterns

Strategy: validation

Validate before calling

// verify all required WPF assemblies are present before constructing KnownThings
static readonly string[] RequiredWpf = {
    "WindowsBase", "PresentationCore", "PresentationFramework", "System.Xaml"
};
bool allPresent = RequiredWpf.All(name =>
    typeSystem.Modules.Any(m => m.AssemblyName == name));
if (!allPresent)
    throw new InvalidOperationException(
        "Load WPF reference assemblies into the type system first.");

Try / catch

try {
    var known = new KnownThings(typeSystem);
} catch (Exception ex) when (ex.Message.StartsWith("Could not resolve known assembly")) {
    // missing WPF reference assembly; widen the resolver search path and retry
}

Prevention

When it happens

Trigger: Building KnownThings for a BAML resource when the IDecompilerTypeSystem supplied does not contain one of the required WPF assemblies (the resolver never loaded PresentationFramework, PresentationCore, or WindowsBase).

Common situations: Decompiling BAML without the WPF reference assemblies on the resolver search path; an assembly resolver that fails to find the framework; stripping framework dependencies; targeting a WPF assembly set with different simple names.

Related errors


AI-assisted analysis of icsharpcode/ILSpy@60c08fcb74 (2026-08-13). Data as JSON: /api/errors/e6b728497b13da09. Report an issue: GitHub.