You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In a Blazor Server project, we experience that a component which has an abstract base component, fails to hot reload if the "code behind" implements abstract properties from the base class when it has a .razor.g.cs extension instead of a standard .razor.cs extension.
We want to have both a .razor.g.cs and .razor.cs partial class in some cases, as the .razor.g.cs is generated code.
The errors we see, look like this:
[Error] c:\Temp\AbstractPartialBugRepro\AbstractPartialBugRepro\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_BuggedComponent_MyComponent_razor.g.cs (line 75): error CS0534: 'MyComponent' does not implement inherited abstract member 'BaseComponent.ComponentType.get'
If we also have the .razor.cs as a partial class, the error points to that class, and not Components_BuggedComponent_MyComponent_razor.g.cs as in this case, but the wording is the same.
It works just fine on initial start, but as soon as we edit the component, hot reload crashes.
If I rename the file from .razor.g.cs to .razor.cs, all works as expected.
Expected Behavior
Hot reload should find the property defined in MyComponent.razor.g.cs and hot reload should work as intended.
Apart from adding the component to Home.razor, all custom code in the repo project is in the BuggedComponent folder. All other files are from the default Blazor Server project.
To begin with, there is an abstract base component class:
public abstract class BaseComponent : ComponentBase
{
protected abstract MyEnum ComponentType { get; }
}
Then there is a partial class for a component (MyComponent.razor.g.cs):
public partial class MyComponent : BaseComponent
{
protected override MyEnum ComponentType => MyEnum.MyComponent;
}
Finally there is a MyComponent.razor which defines the GUI for the component (MyComponent.razor):
@inherits BaseComponent
<h3>My Component</h3>
This all works fine when I first start the app (from Visual Studio), but when I make a change in the Razor file, the hot reload fails with:
[Error] c:\Temp\AbstractPartialBugRepro\AbstractPartialBugRepro\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_BuggedComponent_MyComponent_razor.g.cs (line 75): error CS0534: 'MyComponent' does not implement inherited abstract member 'BaseComponent.ComponentType.get'
If I stop and start the app, it works again.
If I rename the partial class to MyComponent.razor.cs all works as expected.
If I do "dotnet watch run" it also works as expected.
@CRidge , it sounds like you have a file ending in .g.cs, which matches what is in the zip file. There is definitely some code in tooling that assumes .g.cs files are generated; what is your goal in choosing that as the name for an on-disk file in your project?
@phil-allen-msft We're just separating code we generate from code the devs can edit. We're not using source generation - just plain old save-text-to-file in a custom tool. So if it is the specific .g.cs which is the problem, it would be no problem switching to another variant like .gen.cs or something.
Is there an existing issue for this?
Describe the bug
In a Blazor Server project, we experience that a component which has an abstract base component, fails to hot reload if the "code behind" implements abstract properties from the base class when it has a .razor.g.cs extension instead of a standard .razor.cs extension.
We want to have both a .razor.g.cs and .razor.cs partial class in some cases, as the .razor.g.cs is generated code.
The errors we see, look like this:
[Error] c:\Temp\AbstractPartialBugRepro\AbstractPartialBugRepro\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_BuggedComponent_MyComponent_razor.g.cs (line 75): error CS0534: 'MyComponent' does not implement inherited abstract member 'BaseComponent.ComponentType.get'
If we also have the .razor.cs as a partial class, the error points to that class, and not Components_BuggedComponent_MyComponent_razor.g.cs as in this case, but the wording is the same.
It works just fine on initial start, but as soon as we edit the component, hot reload crashes.
If I rename the file from .razor.g.cs to .razor.cs, all works as expected.
Expected Behavior
Hot reload should find the property defined in MyComponent.razor.g.cs and hot reload should work as intended.
Steps To Reproduce
AbstractPartialBugRepro.zip
Apart from adding the component to Home.razor, all custom code in the repo project is in the BuggedComponent folder. All other files are from the default Blazor Server project.
To begin with, there is an abstract base component class:
Then there is a partial class for a component (MyComponent.razor.g.cs):
Finally there is a MyComponent.razor which defines the GUI for the component (MyComponent.razor):
This all works fine when I first start the app (from Visual Studio), but when I make a change in the Razor file, the hot reload fails with:
[Error] c:\Temp\AbstractPartialBugRepro\AbstractPartialBugRepro\obj\Debug\net9.0\Microsoft.CodeAnalysis.Razor.Compiler\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Components_BuggedComponent_MyComponent_razor.g.cs (line 75): error CS0534: 'MyComponent' does not implement inherited abstract member 'BaseComponent.ComponentType.get'
If I stop and start the app, it works again.
If I rename the partial class to MyComponent.razor.cs all works as expected.
If I do "dotnet watch run" it also works as expected.
Exceptions (if any)
No response
.NET Version
9.0.100
Anything else?
dotnet --info
.NET SDK:
Version: 9.0.100
Commit: 59db016f11
Workload version: 9.0.100-manifests.3068a692
MSBuild version: 17.12.7+5b8665660
Runtime Environment:
OS Name: Windows
OS Version: 10.0.26120
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.100\
Visual Studio version info:
The text was updated successfully, but these errors were encountered: