PrismLibrary/Prism · error · ArgumentException
Resources.ValueMustBeOfTypeModuleInfo
Error message
Resources.ValueMustBeOfTypeModuleInfo
What it means
ModuleInfoGroup's explicit IList.Contains(object) implementation throws ArgumentException with Resources.ValueMustBeOfTypeModuleInfo when the supplied value is not null but does not implement IModuleInfo. Because IList is non-generic, Prism must reject wrong-typed items explicitly rather than silently returning false. A null argument raises ArgumentNullException instead.
Solutions
- Use the strongly-typed Contains(IModuleInfo) / Items.Contains method instead of the non-generic IList.Contains overload.
- Ensure the value being tested is a ModuleInfo (or implements IModuleInfo) before calling.
- Replace non-generic collection interactions with IEnumerable<IModuleInfo>/LINQ over Items.
- If handling external/untyped input, type-check first: value is IModuleInfo before invoking Contains.
Example fix
// before IList list = group; bool has = list.Contains(someViewModel); // after bool has = someViewModel is IModuleInfo mi && group.Contains(mi);
Defensive patterns
Strategy: type-guard
Validate before calling
bool exists = value is IModuleInfo mi && group.Contains(mi);
Type guard
static bool GroupContains(ModuleInfoGroup g, object value) => value is IModuleInfo mi && g.Contains(mi);
Try / catch
try { ((IList)group).Contains(value); }
catch (ArgumentException ex) when (ex.Message.Contains("ModuleInfo")) { logger.LogWarning("Non-module item tested against group"); } Prevention
- Use the strongly-typed Contains overload whenever possible.
- Avoid non-generic IList APIs on ModuleInfoGroup.
- Ensure bound/serialized items implement IModuleInfo.
- Handle null separately to distinguish ArgumentNullException.
When it happens
Trigger: Calling IList.Contains on a ModuleInfoGroup (or via non-generic ICollection/IList APIs, data binding, or serializers) with an object that is not a ModuleInfo/IModuleInfo.
Common situations: Legacy non-generic collection code or ArrayList-style checks; WPF binding passing a view-model item instead of a ModuleInfo; LINQ/Cast misuse where a wrong element type reaches the IList API; reflection-based tests probing Contains with sentinel objects.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- A dialog's content must be a FrameworkElement
- Resources.InvalidArgumentAssemblyUri
- Resources.ConfigurationStoreCannotBeNull
- Resources.ModulePathCannotBeNullOrEmpty
- Resources.DirectoryNotFound (string.Format with ModulePath)
AI-assisted analysis of PrismLibrary/Prism@358118cd64 (2026-09-15).
Data as JSON: /api/errors/8d2c3b8349b7f0cd.
Report an issue: GitHub.
Appendix: source
Thrown at src/Wpf/Prism.Wpf/Modularity/ModuleInfoGroup.cs:191
}
/// <summary>
/// Determines whether the <see cref="ModuleInfoGroup"/> contains a specific value.
/// </summary>
/// <param name="value">
/// The <see cref="T:System.Object"/> to locate in the <see cref="ModuleInfoGroup"/>.
/// Must be of type <see cref="IModuleInfo"/>
/// </param>
/// <returns>
/// true if the <see cref="T:System.Object"/> is found in the <see cref="ModuleInfoGroup"/>; otherwise, false.
/// </returns>
bool IList.Contains(object value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!(value is IModuleInfo moduleInfo))
throw new ArgumentException(Resources.ValueMustBeOfTypeModuleInfo, nameof(value));
return Contains(moduleInfo);
}
/// <summary>
/// Determines the index of a specific item in the <see cref="ModuleInfoGroup"/>.
/// </summary>
/// <param name="value">
/// The <see cref="T:System.Object"/> to locate in the <see cref="ModuleInfoGroup"/>.
/// Must be of type <see cref="ModuleInfo"/>
/// </param>
/// <returns>
/// The index of <paramref name="value"/> if found in the list; otherwise, -1.
/// </returns>
public int IndexOf(object value) => _modules.IndexOf((IModuleInfo)value);
/// <summary>
/// Inserts an item to the <see cref="ModuleInfoGroup"/> at the specified index.View on GitHub (pinned to 358118cd64)