{"record":{"id":"2355eff3d120a4e7","repo":"PrismLibrary/Prism","slug":"there-was-an-error-loading-assemblies","errorCode":null,"errorMessage":"There was an error loading assemblies.","messagePattern":"There was an error loading assemblies\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.netcore.cs","lineNumber":71,"sourceCode":"                    select assembly.Location\n                );\n\n                loadedAssemblies.AddRange(assemblies);\n\n                Type loaderType = typeof(InnerModuleInfoLoader);\n\n                if (loaderType.Assembly != null)\n                {\n                    var loader =\n                        (InnerModuleInfoLoader)\n                        childDomain.CreateInstanceFrom(loaderType.Assembly.Location, loaderType.FullName).Unwrap();\n\n                    Items.AddRange(loader.GetModuleInfos(ModulePath));\n                }\n            }\n            catch (Exception ex)\n            {\n                throw new Exception(\"There was an error loading assemblies.\", ex);\n            }\n        }\n\n        private class InnerModuleInfoLoader : MarshalByRefObject\n        {\n            [System.Diagnostics.CodeAnalysis.SuppressMessage(\"Microsoft.Performance\", \"CA1822:MarkMembersAsStatic\")]\n            internal ModuleInfo[] GetModuleInfos(string path)\n            {\n                DirectoryInfo directory = new DirectoryInfo(path);\n\n                ResolveEventHandler resolveEventHandler =\n                    delegate (object sender, ResolveEventArgs args) { return OnReflectionOnlyResolve(args, directory); };\n\n                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += resolveEventHandler;\n\n                Assembly moduleReflectionOnlyAssembly = AppDomain.CurrentDomain.GetAssemblies().First(asm => asm.FullName == typeof(IModule).Assembly.FullName);\n                Type IModuleType = moduleReflectionOnlyAssembly.GetType(typeof(IModule).FullName);\n","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.netcore.cs#L53-L89","documentation":"DirectoryModuleCatalog (.NET Core build) wraps any exception thrown while scanning the directory for module assemblies into a generic Exception with message 'There was an error loading assemblies.' and the original exception as InnerException. Prism does this to give context that the failure occurred during module discovery, since the inner failure may come from arbitrary assembly-loading code.","triggerScenarios":"InnerLoad's loader.GetModuleInfos(ModulePath) throws: a corrupt/partially copied DLL in the folder, an assembly with a bad dependency, a file locked by another process, BadImageFormatException from a mismatched bitness/framework.","commonSituations":"Module DLL built against a different target framework placed in the Modules folder; shadow-copy/antivirus locking files; a plugin assembly referencing a missing third-party dependency; x86/x64 mismatch.","solutions":["Inspect the InnerException to identify the real cause (FileLoadException, BadImageFormatException, ReflectionTypeLoadException, etc.).","Rebuild/replace the offending assembly in the ModulePath folder and ensure all its dependencies are present.","Ensure every DLL in the folder targets a framework compatible with the host app (same bitness, .NET Core vs Framework).","Retry after excluding non-assembly files or stopping processes/antivirus that lock files.","Optionally pre-validate assemblies with AssemblyName.GetAssemblyName in a try/catch before scanning."],"exampleFix":"// before\ncatch (Exception ex)\n{\n    throw new Exception(\"There was an error loading assemblies.\", ex);\n}\n\n// after: fix the cause, e.g. verify the DLL loads before scanning\ntry { var name = AssemblyName.GetAssemblyName(dllPath); }\ncatch (BadImageFormatException e) { logger.LogWarning($\"Skipping {dllPath}: {e.Message}\"); }","handlingStrategy":"try-catch","validationCode":"foreach (var dll in Directory.EnumerateFiles(modulePath, \"*.dll\"))\n{\n    try { AssemblyName.GetAssemblyName(dll); }\n    catch (Exception e) { logger.LogWarning(e, \"Skipping non-loadable assembly {Dll}\", dll); }\n}","typeGuard":"static bool IsLoadableAssembly(string path)\n{\n    try { AssemblyName.GetAssemblyName(path); return true; }\n    catch { return false; }\n}","tryCatchPattern":"try { catalog.Load(); }\ncatch (Exception ex)\n{\n    logger.LogError(ex.InnerException ?? ex, \"Assembly scan failed in {Path}\", modulePath);\n    if (ex.InnerException is ReflectionTypeLoadException rtl)\n        foreach (var le in rtl.LoaderExceptions) logger.LogError(le, \"Loader exception\");\n}","preventionTips":["Always inspect InnerException — the outer message is generic.","Keep module folder free of corrupt/partial files and non-assembly DLLs.","Match target framework and bitness between host and modules.","Deploy all module dependencies together."],"tags":["assembly-loading","reflection","modularity","netcore"],"backgroundTag":"module-init-failed","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}