Open Closed

Overwrite LeptonX component does not work #4064


User avatar
0
ageiter created
  • ABP Framework version: v6.0.1
  • UI type: Blazor Server
  • DB provider: EF Core
  • Exception message and stack trace:
System.ArgumentException: The type 'MyProject.Blazor.Components.Layout.MyMainHeaderToolbar' is not assignable to service 'Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.TopMenu.MainHeader.MainHeaderToolbar'.
   at Autofac.Builder.RegistrationBuilder.CreateRegistration(Guid id, RegistrationData data, IInstanceActivator activator, IResolvePipelineBuilder pipelineBuilder, Service[] services, IComponentRegistration target)
   at Autofac.Builder.RegistrationBuilder.CreateRegistration[TLimit,TActivatorData,TSingleRegistrationStyle](IRegistrationBuilder`3 builder)
   at Autofac.Builder.RegistrationBuilder.RegisterSingleComponent[TLimit,TActivatorData,TSingleRegistrationStyle](IComponentRegistryBuilder cr, IRegistrationBuilder`3 builder)
   at Autofac.ContainerBuilder.Build(IComponentRegistryBuilder componentRegistry, Boolean excludeDefaultModules)
   at Autofac.ContainerBuilder.Build(ContainerBuildOptions options)
   at Volo.Abp.Autofac.AbpAutofacServiceProviderFactory.CreateServiceProvider(ContainerBuilder containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
   at MyProject.Blazor.Program.Main(String[] args) in D:\Projects\MyProject\src\MyProject.Blazor\Program.cs:line 65
  • Steps to reproduce the issue:" I followed the instructions according to the documentation (https://docs.abp.io/en/commercial/latest/themes/lepton-x/blazor?UI=BlazorServer)
  1. Created Razor page MyMainHeaderToolbar.razor (the only content is @Name)
  2. Added MyMainHeaderToolbar.razor.cs with the following content:
using Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.TopMenu.MainHeader;
using Volo.Abp.DependencyInjection;

namespace MyProject.Blazor.Components.Layout
{
    [ExposeServices(typeof(MainHeaderToolbar))]
    [Dependency(ReplaceServices = true)]
    public partial class MyMainHeaderToolbar
    {
        public string Name = "My Main Header Toolbar";
    }
}

Does this still need to be registered somewhere?


6 Answer(s)
  • User Avatar
    0
    ageiter created

    Would be great if I could get an answer on this topic. Thank you.

  • User Avatar
    0
    joe@tronactive.com created

    I am having the same issues. Any ideas?

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    Please make sure the namespaces. There are 2 MainHeaderToolbar classes from 2 different namespaces

    • Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.TopMenu.MainHeader.MainHeaderToolbar
    • Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.SideMenu.MainHeader.MainHeaderToolbar
  • User Avatar
    0
    ageiter created

    @enisn: I use the TopMenu layout. Therefore the namespace should be correct.

    I would have to test if the error still occurs with the new version... but I currently do not come to it, please leave the ticket still open.

  • User Avatar
    0
    enisn created
    Support Team .NET Developer

    It seems, you inherited from different MainHeaderToolbar and replaced different MainHeaderToolbar in the service collection.

    Can you check both MainHeaderToolbar in .razor file and .cs file. Both should be exact same type from the same namespace:

    @inherits Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.TopMenu.MainHeader.MainHeaderToolbar
    
    namespace MyProject.Blazor.Components.Layout
    {
        [ExposeServices(typeof(Volo.Abp.AspNetCore.Components.Web.LeptonXTheme.Components.ApplicationLayout.TopMenu.MainHeader.MainHeaderToolbar))]
        [Dependency(ReplaceServices = true)]
        public partial class MyMainHeaderToolbar
        {
            public string Name = "My Main Header Toolbar";
        }
    }
    
  • User Avatar
    0
    ageiter created

    Thank you for the explanation. This is how it worked. What was missing was the @inherits... in Razor file.

    The documentation contains the sentence "Don't forget to remove repeated attributes from the razor page!". I must have deleted one line too much...

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11