Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
majorimi opened this issue Oct 26, 2020 · 9 comments
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-razor.language severity-major This label is used by an internal tool
Milestone

Comments

@majorimi
Copy link

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>
@majorimi majorimi changed the title .NET 5 Razor build error with templated (generic) component which abstract base class. .NET 5 Razor build error with templated (generic) component with abstract generic base class. Oct 26, 2020
@pranavkm pranavkm added the area-blazor Includes: Blazor, Razor Components label Oct 26, 2020
@mkArtakMSFT
Copy link
Member

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimalistic repro project (ideally a GitHub repo) that illustrates the problem.

@mkArtakMSFT mkArtakMSFT added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Oct 27, 2020
@majorimi
Copy link
Author

majorimi commented Oct 29, 2020

@mkArtakMSFT Ok no problem. I have created a repo with basically the code above. It was very suppressing. NO Build error... For a moment I went crazy but by comparing what can be the difference I have found 1 in the .csproj files.

<nullable>enable</nullable>

And BUILD ERROR. It seems nullable messing with generic base types in Blazor components. Here is the repo. It has only 2 commits first commit will build the second breaks it with Nullable.

image

@ghost ghost added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Oct 29, 2020
@mkArtakMSFT mkArtakMSFT added bug This issue describes a behavior which is not expected - a bug. and removed Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. labels Oct 29, 2020
@mkArtakMSFT mkArtakMSFT added this to the Next sprint planning milestone Oct 29, 2020
@ghost
Copy link

ghost commented Oct 29, 2020

Thanks for contacting us.
We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@SteveSandersonMS
Copy link
Member

Seems like this might be a duplicate of #26971

@SteveSandersonMS SteveSandersonMS added affected-medium This issue impacts approximately half of our customers severity-major This label is used by an internal tool labels Nov 6, 2020 — with ASP.NET Core Issue Ranking
@hesuruio
Copy link

This issue has been plaguing our project for months. It means most of our solution can have nullable enabled but for a particular Blazor project which can't build because of this issue.

@Codinkat
Copy link

@hesuruio I have the exact same issue. The current workaround is to NOT specify the base class in the code-behind file:

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

Specifying the base class in the code-behind file is not technically needed (because the inheritance is defined by @inherits in the razor file), but I used to specify it at both places for more clarity. So until this issue is fixed, I just comment it.

@ghost
Copy link

ghost commented Aug 3, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@ghost
Copy link

ghost commented Oct 22, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@jjonescz
Copy link
Member

Cannot reproduce this in .NET 6 or newer, so I think it's fixed. (Tried that to see if it's fixed by dotnet/razor#8348).

@ghost ghost locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affected-medium This issue impacts approximately half of our customers area-blazor Includes: Blazor, Razor Components bug This issue describes a behavior which is not expected - a bug. feature-razor.language severity-major This label is used by an internal tool
Projects
None yet
Development

No branches or pull requests

10 participants