{"record":{"id":"e6b728497b13da09","repo":"icsharpcode/ILSpy","slug":"could-not-resolve-known-assembly-name","errorCode":null,"errorMessage":"Could not resolve known assembly '{name}'!","messagePattern":"Could not resolve known assembly '(.+?)'!","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"ICSharpCode.BamlDecompiler/Baml/KnownThings.cs","lineNumber":75,"sourceCode":"\t\t\t\tInitStrings();\r\n\t\t\t\tInitResources();\r\n\t\t\t}\r\n\t\t\tcatch (Exception ex)\r\n\t\t\t{\r\n\t\t\t\tthrow new ICSharpCode.Decompiler.DecompilerException(typeSystem.MainModule.MetadataFile, ex.Message, ex);\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tpublic Func<KnownTypes, ITypeDefinition> Types => id => types[id];\r\n\t\tpublic Func<KnownMembers, KnownMember> Members => id => members[id];\r\n\t\tpublic Func<short, string> Strings => id => strings[id];\r\n\t\tpublic Func<short, (string, string, string)> Resources => id => resources[id];\r\n\t\tpublic IModule FrameworkAssembly => assemblies[0];\r\n\t\tIModule ResolveAssembly(string name)\r\n\t\t{\r\n\t\t\tIModule module = typeSystem.Modules.FirstOrDefault(m => m.AssemblyName == name);\r\n\t\t\tif (module == null)\r\n\t\t\t\tthrow new Exception(\"Could not resolve known assembly '\" + name + \"'!\");\r\n\t\t\treturn module;\r\n\t\t}\r\n\r\n\t\tITypeDefinition InitType(IModule assembly, string ns, string name)\r\n\t\t{\r\n\t\t\t// A synthetic stand-in only materializes the types the BAML decompiler explicitly seeds\r\n\t\t\t// here, keeping it bounded to the well-known set. Any other lookup on it returns null.\r\n\t\t\tif (assembly is SyntheticWpfModule synthetic)\r\n\t\t\t\treturn synthetic.RegisterType(ns, name);\r\n\t\t\treturn assembly.GetTypeDefinition(new TopLevelTypeName(ns, name));\r\n\t\t}\r\n\t\tKnownMember InitMember(KnownTypes parent, string name, ITypeDefinition type) => new KnownMember(parent, types[parent], name, type);\r\n\t}\r\n\r\n\tinternal class KnownMember\r\n\t{\r\n\t\tpublic KnownMember(KnownTypes parent, ITypeDefinition declType, string name, ITypeDefinition type)\r\n\t\t{\r","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/icsharpcode/ILSpy/blob/60c08fcb74fcc183130f73c861ed35cf944d0bf1/ICSharpCode.BamlDecompiler/Baml/KnownThings.cs#L57-L93","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":["Ensure the WPF reference assemblies (WindowsBase, PresentationCore, PresentationFramework, System.Xaml) are resolvable by the assembly resolver used to build the type system.","Add the reference-assembly path (e.g. the framework Reference Assemblies directory) to the resolver's search locations.","Build the type system with the BAML resource's parent assembly so transitive references are loaded."],"exampleFix":"// before: resolver only knows the host assembly\nvar ts = new DecompilerTypeSystem(module, minimalResolver, settings);\nvar known = new KnownThings(ts); // may throw 'Could not resolve known assembly ...'\n\n// after: resolver also finds WPF reference assemblies\nvar resolver = new UniversalAssemblyResolver(targetFramework, true, null);\nresolver.AddSearchDirectory(wpfReferenceAssembliesPath);\nvar ts = new DecompilerTypeSystem(module, resolver, settings);\nvar known = new KnownThings(ts);","handlingStrategy":"validation","validationCode":"// verify all required WPF assemblies are present before constructing KnownThings\nstatic readonly string[] RequiredWpf = {\n    \"WindowsBase\", \"PresentationCore\", \"PresentationFramework\", \"System.Xaml\"\n};\nbool allPresent = RequiredWpf.All(name =>\n    typeSystem.Modules.Any(m => m.AssemblyName == name));\nif (!allPresent)\n    throw new InvalidOperationException(\n        \"Load WPF reference assemblies into the type system first.\");","typeGuard":null,"tryCatchPattern":"try {\n    var known = new KnownThings(typeSystem);\n} catch (Exception ex) when (ex.Message.StartsWith(\"Could not resolve known assembly\")) {\n    // missing WPF reference assembly; widen the resolver search path and retry\n}","preventionTips":["Construct the assembly resolver with the WPF reference-assembly directory for the target framework.","Note: the constructor wraps this in a DecompilerException, so catch DecompilerException at the boundary."],"tags":["baml","wpf","assembly-resolution"],"backgroundTag":null,"analyzedSha":"60c08fcb74fcc183130f73c861ed35cf944d0bf1","analyzedAt":"2026-08-13T11:34:51.223Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}