Aspnetcore: Blazor code-behind class inheriting OwningComponentBase won't build

Created on 22 Apr 2020  路  2Comments  路  Source: dotnet/aspnetcore

Describe the bug

When a code behind class of a Blazor component inherits from OwningComponentBase
a Blazor web assembly project will not build.

Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 32.95 ms for /tmp/Website/Website.csproj.
obj/Debug/netstandard2.1/RazorDeclaration/Pages/Index.razor.g.cs(73,26): error CS0263: Partial declarations of 'Index' must not specify different base classes [/tmp/Website/Website.csproj]
obj/Debug/netstandard2.1/RazorDeclaration/Pages/Index.razor.g.cs(76,33): error CS0115: 'Index.BuildRenderTree(RenderTreeBuilder)': no suitable method found to override [/tmp/Website/Website.csproj]

Build FAILED.

obj/Debug/netstandard2.1/RazorDeclaration/Pages/Index.razor.g.cs(73,26): error CS0263: Partial declarations of 'Index' must not specify different base classes [/tmp/Website/Website.csproj]
obj/Debug/netstandard2.1/RazorDeclaration/Pages/Index.razor.g.cs(76,33): error CS0115: 'Index.BuildRenderTree(RenderTreeBuilder)': no suitable method found to override [/tmp/Website/Website.csproj]
    0 Warning(s)
    2 Error(s)

To Reproduce

dotnet new blazorwasm --name Website
cd Website/Pages

```C#

Create a file /Pages/Index.razor.cs to host the partial code-behind class

using Microsoft.AspNetCore.Components;

namespace Website.Pages
{
// public partial class Index : ComponentBase { } // <-- works
public partial class Index : OwningComponentBase { } // <-- DOESN'T WORK
}


Building the project will fail with the errors mentioned in the `Describe the bug` section

### Further technical details
- ASP.NET Core version 3.1.3
- Include the output of `dotnet --info`

.NET Core SDK (reflecting any global.json):
Version: 3.1.201
Commit: b1768b4ae7

Runtime Environment:
OS Name: ubuntu
OS Version: 19.10
OS Platform: Linux
RID: ubuntu.19.10-x64
Base Path: /usr/share/dotnet/sdk/3.1.201/

Host (useful for support):
Version: 3.1.3
Commit: 4a9f85e9f8

.NET Core SDKs installed:
2.2.402 [/usr/share/dotnet/sdk]
3.0.103 [/usr/share/dotnet/sdk]
3.1.201 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.3 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
```

Answered Resolved area-blazor question

All 2 comments

@stoyandimov thanks for contacting us.

The definition of the generated class needs to match exactly the one in your partial. You might be missing @namespace or @inherits OwningComponentBase<YourComponent> in your page definition

Closing for now since we have good coverage for this scenario and we know there are no functional issues in this area. If you get stuck with the given suggestions I would suggest you look at the generated code within the obj folder and work out the differences between the generated class and the partial class.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

githubgitgit picture githubgitgit  路  3Comments

aurokk picture aurokk  路  3Comments

rbanks54 picture rbanks54  路  3Comments

Kevenvz picture Kevenvz  路  3Comments

fayezmm picture fayezmm  路  3Comments