OrchardCMS/OrchardCore · error · ArgumentException
The type must implement the 'IEmailProvider' interface.
Error message
The type must implement the 'IEmailProvider' interface.
What it means
EmailProviderTypeOptions wraps a provider implementation Type and validates at construction that the type implements IEmailProvider. Passing any other type is rejected immediately with this ArgumentException, keeping provider registration type-safe.
Solutions
- Make the registered type implement IEmailProvider (and IAsyncDisposable if needed)
- Fix the type reference in the options setup so it points at the intended provider class
- Add a startup-time assertion/test that all configured provider types implement IEmailProvider
Example fix
// before
services.Configure<EmailProviderOptions>(o => o.Providers["smtp"] = new EmailProviderTypeOptions(typeof(SmtpService)));
// after
public sealed class SmtpEmailProvider : IEmailProvider { ... }
services.Configure<EmailProviderOptions>(o => o.Providers["smtp"] = new EmailProviderTypeOptions(typeof(SmtpEmailProvider))); Defensive patterns
Strategy: validation
Validate before calling
if (!typeof(IEmailProvider).IsAssignableFrom(providerType))
throw new ArgumentException($"{providerType} must implement IEmailProvider before registration"); Type guard
bool IsValidProviderType(Type t) => t is not null && typeof(IEmailProvider).IsAssignableFrom(t);
Try / catch
try { options.Providers[name] = new EmailProviderTypeOptions(type); } catch (ArgumentException ex) { _logger.LogCritical(ex, "Bad email provider registration for {Name}", name); throw; } Prevention
- Register providers only through helper extension methods that enforce the interface
- Keep one class per provider implementing IEmailProvider
- Add a startup test asserting all configured provider types implement IEmailProvider
When it happens
Trigger: Registering an email provider with `new EmailProviderTypeOptions(typeof(SomeService))` where SomeService does not implement IEmailProvider; configuring EmailProviderOptions.Providers dictionary with a wrong or renamed type.
Common situations: Typo or wrong type passed during AddEmailProvider/options configuration; a custom provider class refactored away from IEmailProvider but still referenced in options setup; DI startup code copied from another module without updating the type.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- ' ' is an invalid Email provider name.
- The SMTP pickup directory location is invalid.
- A feature is missing a mandatory 'Id' property in the Module
- Could not resolve extension for type
- Could not resolve main feature for type
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/7a107a4aee3f03e4.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Email.Core/Services/EmailProviderTypeOptions.cs:11
namespace OrchardCore.Email.Services;
public class EmailProviderTypeOptions
{
public Type Type { get; }
public EmailProviderTypeOptions(Type type)
{
if (!typeof(IEmailProvider).IsAssignableFrom(type))
{
throw new ArgumentException($"The type must implement the '{nameof(IEmailProvider)}' interface.");
}
Type = type;
}
public bool IsEnabled { get; set; }
}
View on GitHub (pinned to 4306c0717f)