Reputation: 53
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
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...
Upvotes: 1
Views: 3058
Reputation: 418
Take a look at your .csproj file to see if your partial class is being excluded from compile!
Sometimes Visual studio sometimes borks the csproj file when adding/removing .razor .cs files and you end up with unwanted statements removing your partial class .cs file from the project.
something like...
<ItemGroup>
<Compile Remove="Components\SomeComponent.razor.cs" />
</ItemGroup>
Happens all the time to me. Get rid of these unnecessary compile remove lines to get msbuild/intellisense to see your partial class .cs file.
Upvotes: 5
Reputation: 1
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:
Reference: https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-5.0#namespaces
Upvotes: 1