0
votes

I am running a Blazor test project with Blazorized (which is awesome) and everything works fine. However, there is a small, irritating issue and that is that the code behind (.cs) of one of the (2) pages does not recognize that it is a partial class of a razor file enter image description here

enter image description here

So the protected override async Task OnInitializedAsync() says there is nothing to override. Code works fine however, but this is just bugging me. Tried rebuilding several times, quit Visual Studio and reload solution and also deleting the cache

Hope somebody has a clue...

enter image description here

1
Can you you show your class declaration? (just the declaration, not the body) - Kirk Woll
Just did. Visual Studio seems to think that it is not a partial class, as the name and the keyword partial are greyed out - jeroentjeathome
What version of VS? I don't have this problemn at all. - Henk Holterman
There is something wrong with your version/config/plugins. - Henk Holterman
I faced the same issue when using Visual Studio. You explicitly inherit from ComponentBase and then remote Component, it will be fine then. I use Rider because of these issues. - Imran Faruqi

1 Answers

0
votes

razor file and razor.cs class should have the same namespace. so if you try to change t default namespace in the razor.cs file, it will start giving you this error.

if you don't want to use the default namespace then you can define the same namespace in both files.

you can define the namespace in the razor file like this @namespace TestNameSpace on top. and in partial class like namespace TestNameSpace.

Typically, a component's namespace is derived from the app's root namespace and the component's location (folder) within the app. If the app's root namespace is BlazorSample and the Counter component resides in the Pages folder:

  • The Counter component's namespace is BlazorSample.Pages.
  • The fully qualified type name of the component is BlazorSample.Pages.Counter.

Reference: https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-5.0#namespaces