Skip to content

.NET 5 Razor build error with templated (generic) component with abstract generic base class. #27218

@majorimi

Description

@majorimi

I'm developing some components which have lots of common code. I removed code duplication by created abstract base classes which can be inherited in Blazor code behind files. It works fine with non generic components. Code looks like this:

Abstract base class in MyComponentBase.cs:

public abstract class MyComponentBase : ComponentBase
{ ... }

Razor component Code behind file Component1.razor.cs:

public partial class Component1 : MyComponentBase
{ ... }

Razor component file Component1.razor:

@inherits MyComponentBase

However there is a build error with generic @typeparam components. But both class (generated and codebehind) has the same generic base types:

Severity	Code	Description	Project	File	Line	Suppression State
Error	CS0263	Partial declarations of 'TypeaheadInput<TItem>' must not specify different base classes	Blazor.Components.Typeahead	D:\Projects\GitHub\blazor-components\src\Blazor.Components.Typeahead\obj\Debug\net5.0\RazorDeclaration\TypeaheadInput.razor.g.cs	78	Active

Generic code is very similar to the above code:
Abstract generic base class in MyComponentBase.cs :

public abstract class MyComponentBase<TItem>  : ComponentBase
{ ... }

Razor component Code behind file Component1.razor.cs:

public partial class Component1<TItem> : MyComponentBase<TItem>
{ ... }

Razor component file Component1.razor`:

@typeparam TItem
@inherits MyComponentBase<TItem>

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-mediumThis issue impacts approximately half of our customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-razor.languageseverity-majorThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions