2

I am working with a something.razor file and a code behind Something.razor.cs file. My partial class inherits from SomethingBase which itself inherits from ComponentBase.

This however gives errors

CS0115 .buildrendertree(rendertreebuilder)': no suitable method found to override in partial class CS0263 partial declarations of must not specify different base classes.

However if Something inherits directly from ComponentBase there is no issue.

First question please be gentle. I'll update with code and more detail in the morning if needed.

Power5000
  • 23
  • 2

1 Answers1

7

With a code behind file you have 2 spots where you can specify the base class.

You will always have to specify it in the .razor file because you don't want the default there:

// Something.razor
@inherits SomethingBase 

and then you have a choice in the .razor.cs file:

// Something.razor.cs (a)
partial class Something      // take base class from other part
{
} 

or

// Something.razor.cs (b)
public partial class Something : SomethingBase  // must use the same as other part
{
} 

I would use (a) .

H H
  • 263,252
  • 30
  • 330
  • 514
  • That makes since, What wasn't obvious to me was that the .razor file inherits something by default and that is ComponentBase. so by default having @inherits ComponentBase isn't needed because that is the default but when you change the code behind inheritance then there is a conflict. – Power5000 Sep 15 '21 at 19:42
  • Exactly. [filler filler] – H H Sep 15 '21 at 19:49