Data Localization admin pages fail when Admin Menu is disabled
Describe the bug
When OrchardCore.DataLocalization is enabled and OrchardCore.AdminMenu is disabled, /Admin/DataLocalization/Index—along with every other action on the Data Localization AdminController—returns HTTP 500:
InvalidOperationException: Unable to resolve service for type
'OrchardCore.AdminMenu.Services.IAdminMenuAccessor' while attempting to activate
'OrchardCore.Contents.Services.ContentTypesAdminNodeDataLocalizationProvider'.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(...)
Cause
src/OrchardCore.Modules/OrchardCore.Contents/Startup.cs gates all three data-localization providers on OrchardCore.DataLocalization only:
[RequireFeatures("OrchardCore.DataLocalization")]
public sealed class DataLocalizationStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILocalizationDataProvider, ContentTypeDataLocalizationProvider>();
services.AddScoped<ILocalizationDataProvider, ContentFieldDataLocalizationProvider>();
services.AddScoped<ILocalizationDataProvider, ContentTypesAdminNodeDataLocalizationProvider>();
}
}
The third provider, Services/ContentTypesAdminNodeDataLocalizationProvider.cs, derives from AdminNodeDataLocalizationProvider and requires IAdminMenuAccessor in its constructor.
That service is registered only by the OrchardCore.AdminMenu module’s startup:
services.AddScoped<IAdminMenuAccessor, AdminMenuAccessor>();
OrchardCore.Contents does not depend on OrchardCore.AdminMenu, nor should it.
Because the Data Localization AdminController takes IEnumerable<ILocalizationDataProvider> in its constructor, one unresolvable provider prevents the entire controller from being activated.
Steps to reproduce
-
Set up a tenant with:
OrchardCore.Contents enabled
OrchardCore.DataLocalization enabled
OrchardCore.AdminMenu disabled
This is the default state for a tenant that has never used custom admin menus.
-
Open /Admin/DataLocalization/Index (Configuration → Data Localization).
-
Observe the exception above.
Enabling OrchardCore.AdminMenu makes the page render successfully, confirming the missing-feature dependency.
Expected behavior
The Data Localization page should list the content-type and content-field providers. The admin-node provider should participate only when the OrchardCore.AdminMenu feature is enabled.
Proposed fix
Register the admin-node provider under a startup that requires both features.
RequireFeaturesAttribute accepts params string[], and the same file already contains a startup gated on OrchardCore.AdminMenu (AdminMenuStartup). The smallest change appears to be:
[RequireFeatures("OrchardCore.DataLocalization")]
public sealed class DataLocalizationStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILocalizationDataProvider, ContentTypeDataLocalizationProvider>();
services.AddScoped<ILocalizationDataProvider, ContentFieldDataLocalizationProvider>();
}
}
[RequireFeatures("OrchardCore.DataLocalization", "OrchardCore.AdminMenu")]
public sealed class AdminMenuDataLocalizationStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<ILocalizationDataProvider, ContentTypesAdminNodeDataLocalizationProvider>();
}
}
This would not change behavior for tenants with both features enabled.
Environment
-
Orchard Core 4.0.0-preview
- Observed on
preview-20119
- The registration is unchanged on
main as of today
-
.NET 10
-
Windows 11
-
SQLite (the tenant database is irrelevant to the bug)
-
Reproduced on three tenants with different default cultures (en and el)
Data Localization admin pages fail when Admin Menu is disabled
Describe the bug
When
OrchardCore.DataLocalizationis enabled andOrchardCore.AdminMenuis disabled,/Admin/DataLocalization/Index—along with every other action on the Data LocalizationAdminController—returns HTTP 500:Cause
src/OrchardCore.Modules/OrchardCore.Contents/Startup.csgates all three data-localization providers onOrchardCore.DataLocalizationonly:The third provider,
Services/ContentTypesAdminNodeDataLocalizationProvider.cs, derives fromAdminNodeDataLocalizationProviderand requiresIAdminMenuAccessorin its constructor.That service is registered only by the
OrchardCore.AdminMenumodule’s startup:OrchardCore.Contentsdoes not depend onOrchardCore.AdminMenu, nor should it.Because the Data Localization
AdminControllertakesIEnumerable<ILocalizationDataProvider>in its constructor, one unresolvable provider prevents the entire controller from being activated.Steps to reproduce
Set up a tenant with:
OrchardCore.ContentsenabledOrchardCore.DataLocalizationenabledOrchardCore.AdminMenudisabledThis is the default state for a tenant that has never used custom admin menus.
Open
/Admin/DataLocalization/Index(Configuration→Data Localization).Observe the exception above.
Enabling
OrchardCore.AdminMenumakes the page render successfully, confirming the missing-feature dependency.Expected behavior
The Data Localization page should list the content-type and content-field providers. The admin-node provider should participate only when the
OrchardCore.AdminMenufeature is enabled.Proposed fix
Register the admin-node provider under a startup that requires both features.
RequireFeaturesAttributeacceptsparams string[], and the same file already contains a startup gated onOrchardCore.AdminMenu(AdminMenuStartup). The smallest change appears to be:This would not change behavior for tenants with both features enabled.
Environment
Orchard Core
4.0.0-previewpreview-20119mainas of today.NET 10
Windows 11
SQLite (the tenant database is irrelevant to the bug)
Reproduced on three tenants with different default cultures (
enandel)