question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error BLAZOR102 when using CSS preprocessing

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Follow up of https://github.com/dotnet/aspnetcore/issues/38374 I’ve successfully managed to use the documentation to copy compiled files to the wwwroot folder using MSBuild.

Now I would like to do the same with Blazor scoped css, but every tutorial I’ve found just places the compiled CSS file inside the git repository instead of the recommended obj/ folder.

I’ve update my repo here https://github.com/JohnKiller/TestCopyFile

Inside RazorClassLibrary1/RazorClassLibrary1.csproj I’ve placed a fake compilation step that just copies the scss in the obj/ folder and then includes it:

<Target Name="NpmRunBuild" BeforeTargets="AssignTargetPaths" Inputs="Component1.razor.scss" Outputs="$(IntermediateOutputPath)Component1.razor.css">
	<Exec Command="copy Component1.razor.scss $(IntermediateOutputPath)Component1.razor.css" />

	<ItemGroup>
		<Content Include="$(IntermediateOutputPath)Component1.razor.css" Link="Component1.razor.css" />
	</ItemGroup>
</Target>

But this is the error I get:

obj\Debug\net6.0\Component1.razor.css : error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

To me it looks like since the path is inside obj\Debug the framework misinterprets the path to be outside the component project location and refuses to bundle it.

Expected Behavior

I would like this solution to work so I can avoid adding the compiled css file to the git repo and keep only the source scss. Using .gitignore is not an option because it causes the problem described in https://github.com/dotnet/aspnetcore/issues/38374

Steps To Reproduce

Build https://github.com/JohnKiller/TestCopyFile

Exceptions (if any)

obj\Debug\net6.0\Component1.razor.css : error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

.NET Version

6.0.101

Anything else?

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
iykeypatcommented, Oct 31, 2022

error BLAZOR102: The scoped css file 'obj\Debug\net6.0\Component1.razor.css' was defined but no associated razor component or view was found for it.

Solution: I recreated the razor component with a different name, copied my code to it, scoped the css file again and copied the css from the former one to it and voila, the error stopped.

1reaction
KurtGarrettALScommented, Jan 7, 2023

Same issue as reported above . To test; I created new Blazor Server solution targeting .net 6. Then created Razor component CustomNotFound.razor and then CustomNotFound.razor.css. VS attaches the css file correctly but then throws error:

Severity Code Description Project File Line Suppression State Error BLAZOR102 The scoped css file ‘Pages\CustomNotFound.razor.css’ was defined but no associated razor component or view was found for it. CustomerService C:\VSApps\Development\CustomerService\CustomerService\Pages\CustomNotFound.razor.css 1

ScopedCssErrorScreenshot

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core Blazor CSS isolation
Learn how CSS isolation scopes CSS to Razor components, which can simplify CSS and avoid collisions with other components or libraries.
Read more >
How to fix More than one scoped css files were found for ...
I have just css file for my razor component, but when I try to build it I get the More than one scoped...
Read more >
CSS Isolation In Blazor
The CSS isolation in the Blazor component is by default enabled and to use it create a ".razor.css" file matching with component name....
Read more >
Use CSS isolation in your Blazor projects - Dave Brock
This post discusses how to use CSS isolation with the latest preview bits, a feature adored by those in the Angular and Vue...
Read more >
CSS Preprocessors: How to Debug and Troubleshoot Issues
This can help you debug and troubleshoot issues with CSS preprocessors by showing you the exact line and file where an error or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found