Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor - .NET 8 - Can't load styles.css from external assembly

Is there a problem with .NET 8 and Blazor or just a problem with my project? I have a common assembly so I can build as either Maui or Web Assembly. I've done this before. I have a .NET 6 and .NET 7 projects, set up the same way, where it's all working as expected.

So, I think it's all set up ok:

<link rel="stylesheet" href="_content/CommonAssembly/css/bootstrap/bootstrap.min.css" /> <!-- Loads -->
<link rel="stylesheet" href="_content/CommonAssembly/css/app.css" /> <!-- Loads -->
<link rel="stylesheet" href="CommonAssembly.styles.css" /> <!-- Does not load -->

The styles.css file about does not load.

The main layout and the individual views are also in CommonAssembly. These also load.

But when the app launches and it tries to load:

https://0.0.0.0/CommonAssembly.styles.css

The file is not found and can't be loaded.

The external assembly is registered in my routes:

<Router AppAssembly="@typeof(MauiProgram).Assembly" AdditionalAssemblies="new[] {typeof(MainLayout).Assembly}">

Has anyone come across this with .NET 8? Can anyone suggest something I can try?

like image 212
user794720 Avatar asked Jun 03 '26 12:06

user794720


1 Answers

My mistake was assuming the isolated css would be loaded from the common assembly. When the project builds, it builds the isolated CSS into the main assembly so I had to replace:

<link rel="stylesheet" href="CommonAssembly.styles.css" />

With:

<link rel="stylesheet" href="MainAssembly.styles.css" />
like image 103
user794720 Avatar answered Jun 06 '26 01:06

user794720