dotnet / razor

Compiler and tooling experience for Razor ASP.NET Core apps in Visual Studio, Visual Studio for Mac, and VS Code.
https://asp.net
MIT License
494 stars 191 forks source link

VS Code complaining that Routes element is not a component, but it totally is #9613

Open DamianEdwards opened 10 months ago

DamianEdwards commented 10 months ago

See this image: image

The editor is complaining that <Routes /> looks like a component but isn't, but the Routes.razor file is right there in the directory. Note that the <HeadOutlet> is detected as a component just fine.

project.razor.vscode.bin.zip

Repro is at https://github.com/dotnet/aspire/tree/main/samples/eShopLite

DamianEdwards commented 10 months ago

Adding Razor Log razorlog.log

davidwengier commented 10 months ago

From the logs it looks like this was actually reproing for https://github.com/dotnet/aspire-samples/tree/main/samples/eShopLite

Crux of the issue is this:

[Client - 2:00:38 PM] (Warning) razor.provideDynamicFileInfo failed with CodeExpectedError: cannot open virtualCSharp-razor:/d%3A/src/GitHub/dotnet/aspire-samples/samples/eShopLite/eShopLite.Frontend/Components/Routes.razor__virtual.cs. Detail: Unable to resolve resource virtualCSharp-razor:/d%3A/src/GitHub/dotnet/aspire-samples/samples/eShopLite/eShopLite.Frontend/Components/Routes.razor__virtual.cs

Fowler hit that once, and I reproed it once too, but it went away after I bumped up the logging and reloaded, sadly. Not sure why, but VS Code doesn't want to open our generated file. That means we can't update Roslyn with the generated code, and therefore means components aren't discovered - they don't exist in the Roslyn compilation, it just has empty files. I can't see any issues with file paths or anything that would cause issues though.

Opening https://github.com/dotnet/aspire/tree/main/samples/eShopLite fails for me because the build system puts the obj folder in artifacts in the repo root, which is not part of the VS Code workspace. https://github.com/dotnet/roslyn/pull/70913 might fix that, unintentionally, but makes me think thats not what you were doing. Nothing works if you do that :)

DamianEdwards commented 10 months ago

Hah, it's likely I just got confused when pointing at which instance of the sample I was using. Are you able to repro if opening https://github.com/dotnet/aspire-samples/tree/main/samples/eShopLite?

davidwengier commented 10 months ago

I hit it once, but then couldn't hit it again, sadly. Could be a startup issue, perhaps a race condition around when we register the handler for the virtualCSharp-razor:/ scheme.

DamianEdwards commented 10 months ago

I did a git clean -xdf and it went away so it seems related to transient files created during the inner-loop? Perhaps got out of sync somehow?