Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor WebAssembly CSS isolation scoped identities doesn't match

In a Blazor WebAssembly .NET Core hosted application, after changing the {PROJECT NAME}.Client project name to "{PROJECT NAME}.Admin" (changing the client project name), scope identifies for CSS isolation in the {PROJECT NAME}.Admin.styles.css file and rendered objects in the DOM are different.


What I did

I created a .NET core hosted Blazor WebAssembly application with authentication. Ran the application. Worked fine.

Then I changed the project name of {PROJECT NAME}. Client project to "{PROJECT NAME}.Admin". And changed basically everywhere there was "Client" to "Admin".

  • Everywhere the namespace was mentioned
  • The Client Folder in the project folder

Then I added the project references.

When I ran the project... This was the landing page.


The Issue

All the functionality works fine. All the components are rendered. But only Bootstrap styling is applied to the MainLayout and NavMenu components as they use CSS isolation. The isolated CSS files generated files scope identities aren't the same as what is rendered to the DOM.

Image of {PROJECT NAME}.Admin.styles.css file

Image of Rendered HTML

The page renders fine if I change the scope Identities manually. But it resets when I Run the application the next time.


I'm just playing around with Blazor. So I'm expecting a fix to this problem rather than some alternate method or workaround to do the styling. I'm new to online forums. Sorry for providing unnecessary information or providing less information. Please request any additional information needed.

like image 805
TharinduSK Avatar asked Jan 25 '23 13:01

TharinduSK


2 Answers

Deleting the CSS isolated files and creating them again from the beginning made it work! How ever rebuilding the solution or cleaning the solution did not work. Still no clue of what was going on.

like image 167
TharinduSK Avatar answered Jan 27 '23 11:01

TharinduSK


What worked for me was deleting the obj and bin folders, besides renaming the link to the css file to {AssemblyName}.styles.css. Setting it to ProjectName does not work if it differs from AssemblyName.

This way it was not necessary for me to delete and recreate the specific css files. Note: I'm using Blazor Server with ASP.NET 5

like image 26
jamie Avatar answered Jan 27 '23 11:01

jamie