PrismLibrary/Prism · error · ArgumentNullException

Value cannot be null. (Parameter 'name')

Error message

Value cannot be null. (Parameter 'name')

What it means

The ModuleInfo(string name, string type, params string[] dependsOn) constructor throws ArgumentNullException when the module name is null or whitespace. Every module in the Prism catalog must have a non-empty ModuleName used for dependency resolution and lookup.

Solutions

  1. Supply a non-empty module name: new ModuleInfo("FooModule", typeof(FooModule).AssemblyQualifiedName)
  2. Validate configuration values before constructing ModuleInfo
  3. If loading from config, fix the missing/empty module name entry

Example fix

// before
var info = new ModuleInfo(config.Name, config.Type); // config.Name is ""
// after
if (string.IsNullOrWhiteSpace(config.Name)) throw new InvalidOperationException("Module name missing from configuration");
var info = new ModuleInfo(config.Name, config.Type);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrWhiteSpace(moduleConfig.Name))
    throw new InvalidOperationException($"Module '{moduleConfig.Type}' has no name in configuration");
var info = new ModuleInfo(moduleConfig.Name, moduleConfig.Type);

Try / catch

try
{
    var info = new ModuleInfo(name, type);
}
catch (ArgumentNullException ex) when (ex.ParamName == "name")
{
    logger.LogError(ex, "Module name missing — check moduleCatalog configuration");
    throw;
}

Prevention

When it happens

Trigger: new ModuleInfo(null, "MyApp.Modules.FooModule") or new ModuleInfo("", ...) or new ModuleInfo(" ", ...); typically the name comes from configuration that is missing or empty.

Common situations: Module catalog configuration with a missing or empty name attribute; programmatic catalog building that forwards an unset variable; deserializing module definitions from a file with absent keys.

Related errors


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

Appendix: source

Thrown at src/Maui/Prism.Maui/Modularity/ModuleInfo.cs:34

{
    /// <summary>
    /// Initializes a new empty instance of <see cref="ModuleInfo"/>.
    /// </summary>
    public ModuleInfo()
    {
    }

    /// <summary>
    /// Initializes a new instance of <see cref="ModuleInfo"/>.
    /// </summary>
    /// <param name="name">The module's name.</param>
    /// <param name="type">The module <see cref="Type"/>'s AssemblyQualifiedName.</param>
    /// <param name="dependsOn">The modules this instance depends on.</param>
    /// <exception cref="ArgumentNullException">An <see cref="ArgumentNullException"/> is thrown if <paramref name="dependsOn"/> is <see langword="null"/>.</exception>
    public ModuleInfo(string name, string type, params string[] dependsOn)
    {
        if (string.IsNullOrWhiteSpace(name))
            throw new ArgumentNullException(nameof(name));
        if (dependsOn == null)
            throw new ArgumentNullException(nameof(dependsOn));

        ModuleType = Type.GetType(type) ?? throw new ArgumentNullException(nameof(type));
        ModuleName = name;
        foreach (string dependency in dependsOn)
        {
            if (!DependsOn.Contains(dependency))
            {
                DependsOn.Add(dependency);
            }
        }
    }

    /// <summary>
    /// Initializes a new instance of <see cref="ModuleInfo"/>.
    /// </summary>
    /// <param name="name">The module's name.</param>

View on GitHub (pinned to 358118cd64)