8

If I start a Blazor server from scratch. Then right-click the project and click rename.

All the namespaces change(EditedProjectName.Pages) but the using statements keep the old references(OriginalProjectName.Pages).

This is fairly easy to overcome with Find and replace OriginalProjectName.Pages => replace with => EditedProjectName.Pages

Now the issue. Seemly randomly the site launches without proper css. The same output as I get if I comment out the static CSS in {PROJECT NAME}.styles.css which makes the sidebar etc disappear incorrect blazor index page view

Any idea of how the project name change can cause this issue and how I can solve or troubleshoot it?

3
  • Did you a) search for the old name? It's also used in _Layout to load a css. b) do a Build|Clean and a Build|Rebuild? c) hit Ctrl+F5 in the Browser? Commented Feb 20, 2022 at 7:18
  • You can also try to use clean solution and then in the browser F12 -> application and the clear site data. Sometimes it can be a cashing issue. Commented Feb 20, 2022 at 10:38
  • 1
    I tried Rebuild but your Build|Clean advice solved it right away. A good lesson that I won't forget! Thanks a lot! @JeremiedeVos Commented Feb 20, 2022 at 10:58

7 Answers 7

12

The issue disappeared when I did a Build|Clean and a Build|Rebuild.

Sign up to request clarification or add additional context in comments.

1 Comment

mine is still not working after following this. Checked all other suggestions, even tried using the oldproject.css but without a result. Any idea why ?
6

I was able to get it working while preserving the ability to rename the project by getting the name of the assembly using reflection in my _Host.cshtml file:

<link href="@(System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".styles.css")" rel="stylesheet" />

You would also be able to inject it as a singleton configuration in your DI container and inject it into the cshtml file.

1 Comment

For Blazor .Net8 I added this to the App.razor file in the Components folder.
4

Visual Studio Build Menu -> Clean Solution

AND

deleting the bin and obj folders in the project folder finally worked.

1 Comment

Rebuild will do the same - a rebuild is a clean and build together
3

When you rename a Blazor project, be sure to rename also the Razor CSS file bundle, referenced in

/Pages/_Layout.cshtml

as

<!-- Important: these are the razor css'es built at runtime -->
<link href="[Your_Project_Name].styles.css" rel="stylesheet" />

Comments

2

For others experience the same problem, I found a solution and documented it over here: Blazor WebAssembly CSS isolation scoped identities doesn't match

In summary; change the modified dates of your base blazor CSS files to force them to be re-transpiled (like Layout/MainLayout.razor.css and Layout/NavMenu.razor.css)

Comments

0

After trying all of the suggestions here, I also needed to delete browsing data, and now the site loads fine.

Comments

0

My issue was fixed when I changed the wwwroot/index.html
and changed this line from: <link href="{OldProjectName}.styles.css" rel="stylesheet" />
into: <link href="{NewProjectName}.styles.css" rel="stylesheet" />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.