OrchardCMS/OrchardCore · error · ArgumentException
File path must be a non-empty string.
Error message
File path must be a non-empty string.
What it means
AddTenantJsonFile registers a tenant-scoped JSON configuration source for the given builder. A null/empty path cannot identify the JSON file, so the extension throws ArgumentException with paramName 'path', mirroring the framework's AddJsonFile validation.
Solutions
- Pass a valid non-empty file name, typically $"appsettings.{tenantName}.json".
- Validate/guard the path at the call site before building configuration.
- If the file may legitimately be absent, still pass a real name and set optional: true.
- Trace where the empty path originates (ShellSettings.Configuration) and fix the tenant setup.
Example fix
// before
builder.AddTenantJsonFile(tenantSettings.File);
// after
if (!string.IsNullOrEmpty(tenantSettings.File))
{
builder.AddTenantJsonFile(tenantSettings.File, optional: true);
} Defensive patterns
Strategy: validation
Validate before calling
ArgumentException.ThrowIfNullOrWhiteSpace(path); // .NET 8+, or: if (string.IsNullOrWhiteSpace(path)) throw new ArgumentException(nameof(path));
Type guard
bool HasTenantFile(ShellSettings s) => !string.IsNullOrWhiteSpace(s.File);
Try / catch
try { builder.AddTenantJsonFile(path, optional: true); }
catch (ArgumentException ex) when (ex.ParamName == "path") { /* skip optional tenant config */ } Prevention
- Default tenant config file names at tenant creation time
- Use optional:true for per-tenant files that may not exist
- Guard variables derived from ShellSettings before building configuration
When it happens
Trigger: Calling configurationBuilder.AddTenantJsonFile(path) or AddTenantJsonFile(provider, path, optional, reloadOnChange) with path == null, path == "" or whitespace-only string.
Common situations: The tenant's appsettings file name comes from ShellSettings or a config value that is unset (e.g. a new tenant not yet configured), a renamed settings property, or passing an unvalidated variable built at runtime.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- A feature is missing a mandatory 'Id' property in the Module
- The 'Default' tenant can't be removed.
- The tenant ' ' can't be removed as it is neither…
- Top level JSON element must be an object. Instead
- Can't use the numeric key
AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13).
Data as JSON: /api/errors/213a98b8a8241a2a.
Report an issue: GitHub.
Appendix: source
Thrown at src/OrchardCore/OrchardCore.Abstractions/Modules/Overrides/Configuration/TenantJsonConfigurationExtensions.cs:73
/// <summary>
/// Adds a JSON configuration source to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="provider">The <see cref="IFileProvider"/> to use to access the file.</param>
/// <param name="path">Path relative to the base path stored in
/// <see cref="IConfigurationBuilder.Properties"/> of <paramref name="builder"/>.</param>
/// <param name="optional">Whether the file is optional.</param>
/// <param name="reloadOnChange">Whether the configuration should be reloaded if the file changes.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static IConfigurationBuilder AddTenantJsonFile(this IConfigurationBuilder builder, IFileProvider? provider, string path, bool optional, bool reloadOnChange)
{
// ThrowHelper.ThrowIfNull(builder);
ArgumentNullException.ThrowIfNull(builder);
if (string.IsNullOrEmpty(path))
{
// throw new ArgumentException(SR.Error_InvalidFilePath, nameof(path));
throw new ArgumentException("File path must be a non-empty string.", nameof(path));
}
return builder.AddTenantJsonFile(s =>
{
s.FileProvider = provider;
s.Path = path;
s.Optional = optional;
s.ReloadOnChange = reloadOnChange;
s.ResolveFileProvider();
});
}
/// <summary>
/// Adds a JSON configuration source to <paramref name="builder"/>.
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param>
/// <param name="configureSource">Configures the source.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>View on GitHub (pinned to 4306c0717f)