PrismLibrary/Prism · error · ArgumentNullException

moduleInfo

Error message

moduleInfo

What it means

The LoadModuleCompletedEventArgs constructor throws ArgumentNullException when the moduleInfo parameter is null. Prism requires every load-completed event argument to carry a non-null IModuleInfo; the optional error parameter is separate. This is a fail-fast guard so downstream event handlers never need to null-check ModuleInfo.

Solutions

  1. Pass the actual IModuleInfo instance that was being loaded; on failure still supply it with the Exception in the error parameter rather than null.
  2. If you only have a module name, resolve the IModuleInfo from the catalog before raising LoadModuleCompleted.
  3. In tests, construct a stub IModuleInfo (e.g. new ModuleInfo("TestModule")) instead of passing null.

Example fix

// before
var args = new LoadModuleCompletedEventArgs(null, ex);
// after
var moduleInfo = catalog.Modules.FirstOrDefault(m => m.ModuleName == moduleName) ?? new ModuleInfo(moduleName);
var args = new LoadModuleCompletedEventArgs(moduleInfo, ex);
Defensive patterns

Strategy: validation

Validate before calling

if (moduleInfo == null) throw new InvalidOperationException("Cannot raise LoadModuleCompleted without an IModuleInfo");
var args = new LoadModuleCompletedEventArgs(moduleInfo, error);

Type guard

bool IsValidArgs(LoadModuleCompletedEventArgs a) => a?.ModuleInfo != null;

Try / catch

try
{
    var args = new LoadModuleCompletedEventArgs(moduleInfo, error);
}
catch (ArgumentNullException ex) when (ex.ParamName == nameof(moduleInfo))
{
    logger.LogError(ex, "Attempted to raise load-completed with null module info");
}

Prevention

When it happens

Trigger: Directly calling new LoadModuleCompletedEventArgs(null, someException) instead of relying on the module loading service (ModuleInitializer/ModuleManager) to construct the args.

Common situations: Custom IModuleManager implementations, unit tests that build the event args by hand, or reflection-based wrappers that pass a null module record after a failed module load lookup.

Related errors


AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15). Data as JSON: /api/errors/3b8cf7edef045f10. Report an issue: GitHub.

Appendix: source

Thrown at src/Prism.Core/Modularity/LoadModuleCompletedEventArgs.cs:21

using System;

namespace Prism.Modularity
{
    /// <summary>
    /// Provides completion information after a module is loaded, or fails to load.
    /// </summary>
    public class LoadModuleCompletedEventArgs : EventArgs
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="LoadModuleCompletedEventArgs"/> class.
        /// </summary>
        /// <param name="moduleInfo">The module info.</param>
        /// <param name="error">Any error that occurred during the call.</param>
        public LoadModuleCompletedEventArgs(IModuleInfo moduleInfo, Exception error)
        {
            if (moduleInfo == null)
            {
                throw new ArgumentNullException(nameof(moduleInfo));
            }

            this.ModuleInfo = moduleInfo;
            this.Error = error;
        }

        /// <summary>
        /// Gets the module info.
        /// </summary>
        /// <value>The module info.</value>
        public IModuleInfo ModuleInfo { get; private set; }

        /// <summary>
        /// Gets any error that occurred
        /// </summary>
        /// <value>The exception if an error occurred; otherwise null.</value>
        public Exception Error { get; private set; }

View on GitHub (pinned to 358118cd64)