PrismLibrary/Prism · error · Exception
There was an error loading assemblies.
Error message
There was an error loading assemblies.
What it means
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.
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.
Example fix
// before
catch (Exception ex)
{
throw new Exception("There was an error loading assemblies.", ex);
}
// after: fix the cause, e.g. verify the DLL loads before scanning
try { var name = AssemblyName.GetAssemblyName(dllPath); }
catch (BadImageFormatException e) { logger.LogWarning($"Skipping {dllPath}: {e.Message}"); } Defensive patterns
Strategy: try-catch
Validate before calling
foreach (var dll in Directory.EnumerateFiles(modulePath, "*.dll"))
{
try { AssemblyName.GetAssemblyName(dll); }
catch (Exception e) { logger.LogWarning(e, "Skipping non-loadable assembly {Dll}", dll); }
} Type guard
static bool IsLoadableAssembly(string path)
{
try { AssemblyName.GetAssemblyName(path); return true; }
catch { return false; }
} Try / catch
try { catalog.Load(); }
catch (Exception ex)
{
logger.LogError(ex.InnerException ?? ex, "Assembly scan failed in {Path}", modulePath);
if (ex.InnerException is ReflectionTypeLoadException rtl)
foreach (var le in rtl.LoaderExceptions) logger.LogError(le, "Loader exception");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Resources.ModulePathCannotBeNullOrEmpty
- Properties.Resources.FailedToGetType (string.Format with…
- No matching event ' ' on attached type
- Unable to find
- Value cannot be null. (Parameter 'name')
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/2355eff3d120a4e7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Modularity/DirectoryModuleCatalog.netcore.cs:71
select assembly.Location
);
loadedAssemblies.AddRange(assemblies);
Type loaderType = typeof(InnerModuleInfoLoader);
if (loaderType.Assembly != null)
{
var loader =
(InnerModuleInfoLoader)
childDomain.CreateInstanceFrom(loaderType.Assembly.Location, loaderType.FullName).Unwrap();
Items.AddRange(loader.GetModuleInfos(ModulePath));
}
}
catch (Exception ex)
{
throw new Exception("There was an error loading assemblies.", ex);
}
}
private class InnerModuleInfoLoader : MarshalByRefObject
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
internal ModuleInfo[] GetModuleInfos(string path)
{
DirectoryInfo directory = new DirectoryInfo(path);
ResolveEventHandler resolveEventHandler =
delegate (object sender, ResolveEventArgs args) { return OnReflectionOnlyResolve(args, directory); };
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += resolveEventHandler;
Assembly moduleReflectionOnlyAssembly = AppDomain.CurrentDomain.GetAssemblies().First(asm => asm.FullName == typeof(IModule).Assembly.FullName);
Type IModuleType = moduleReflectionOnlyAssembly.GetType(typeof(IModule).FullName);
View on GitHub (pinned to 358118cd64)