razor icon indicating copy to clipboard operation
razor copied to clipboard

Blazor Server does not see RCL components

Open mayur-ekbote opened this issue 2 years ago • 22 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

I recently updated to .net 8. I have both VS 2022 and 2022 Preview version installed.

  1. When I run this project from Visual Studio Preview, the app runs fine.
  2. If I publish the project to a folder, the app cannot find static assets of the RCL (error in the browser console - 404 CSS not found)
  3. If I run this project from the non-preview version of Visual Studio, I still have the same problem

That was for an existing component. Now, if I add any new component to the RCL, it is not recognized by either of these versions at all! If I create SomeComponent.razor and use it anywhere in the Blazor server project, <SomeComponent /> gets rendered as <somecomponent/> and obviously does appear on the page.

I have tried:

  1. Removing everything in .vs .bin .obj folders everywhere.
  2. Repairing both VS editions
  3. Creating Directory.Build.props and adding
 <PropertyGroup>
	  <AccelerateBuildsInVisualStudio>false</AccelerateBuildsInVisualStudio>
  </PropertyGroup>
  1. Creating another RCL and creating a component in that (same problem)

Now, here is the kicker: I wanted to create a repro, but I did not see the .net 8 in the create new project wizard! (.net 8 is installed and is being used by VS for running the app.)

Is there anyway to diagnose this? I remember encountering this problem a couple of years ago, but it was fixed.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

No response

mayur-ekbote avatar Dec 02 '23 12:12 mayur-ekbote

Misread - Blazor Server

garrettlondon1 avatar Dec 03 '23 16:12 garrettlondon1

Can you please elaborate? I am not sure what you mean by AdditionalAssemblies

mayur-ekbote avatar Dec 04 '23 05:12 mayur-ekbote

Thank you for filing this issue. In order for us to investigate this issue, please provide a minimal repro project that illustrates the problem without unnecessary code. Please share with us in a public GitHub repo because we cannot open ZIP attachments, and don't include any confidential content.

ghost avatar Dec 04 '23 17:12 ghost

@surayya-MS It is not possible to provide a repro:

Now, here is the kicker: I wanted to create a repro, but I did not see the .net 8 in the create new project wizard! (.net 8 is installed and is being used by VS for running the app.)

Also, this is not a new issue. Please see: #5001

Is there anyway to diagnose this? I remember encountering this problem a couple of years ago, but it was fixed.

mayur-ekbote avatar Dec 04 '23 19:12 mayur-ekbote

@mayur-ekbote , could you please create a .net 7 Blazor Server app and then update to .net 8?

surayya-MS avatar Dec 06 '23 17:12 surayya-MS

Here's what I tried:

  • Created a Blazor Server app targeting .NET 7
  • Updated the Blazor Server app to target .NET 8
  • Added a Razor Class Library and referenced it from the app
  • Added <RazorClassLibrary1.Component1 /> to the Index page
  • Published the app locally to a folder and ran the published app

It seems to work fine:

image

danroth27 avatar Dec 06 '23 18:12 danroth27

I followed the 'create .net 7 -> upgrade to .net 8' path and the issues seems to be stemming from VS losing intellisense.

  1. Create a .net 7 Blazor Server app
  2. Create a .net 7 RCL
  3. Refer RCL from the Blazor app and use a component from the RCL. It works fine
  4. Now upgrade both projects using Upgrade tool.
  5. Create a folder in RCL and add a component to that folder.
  6. At this point, the IDE neither sees the newly created folder, nor does it see the component itself.
  7. However, the runtime seems to be working once the reference is added.

(Please refer to attached video for the remaining)

https://1drv.ms/v/s!Am6vW_yz2H5DhOMuAYtoelJ6hW-Kyw?e=5Y72sS

Ideally, IntelliSense should tell that TestComponent is inside ReferenceLibrary.InnerComponent. Not only does it not, but also doesn't recognize the component even after it is added and program is run.

In a project with many folder hierarchies, it is hard to know which inner folders have been referred to - since IntelliSense doesn't even see those namespaces.

However, the divergence in the behavior between VS preview and VS seems to have been fixed after the last release of VS.

mayur-ekbote avatar Dec 11 '23 10:12 mayur-ekbote

However, the runtime seems to be working once the reference is added.

Do you mean it works fine when you run or if you build/run from the command-line?

Now upgrade both projects using Upgrade tool.

This might leave the projects in an unknown state. Does cleaning (physically removing) the bin/obj folders after this step makes the issue go away?

javiercn avatar Dec 11 '23 18:12 javiercn

Do you mean it works fine when you run or if you build/run from the command-line?

After the last update, it works fine from VS too. However, the IDE does not recognize the component. The actual output on running the project is fine (check the ending of the video). Which is to say that the original problem doesn't arise.

This might leave the projects in an unknown state. Does cleaning (physically removing) the bin/obj folders after this step makes the issue go away?

In a small repro, it does go away. However, in my actual project, it doesn't. (See the screenshot). Basically, I end up coding blind since IntelliSense shows no hints - rather keeps saying if I want to create a new component from the tag. The actual application works as expected. I haven't checked with the additional CSS yet.

UserInterface

mayur-ekbote avatar Dec 11 '23 20:12 mayur-ekbote

@mayur-ekbote thanks for the additional details.

It seems that this is tooling related, so I'll let them chime in here as they are the experts.

javiercn avatar Dec 12 '23 15:12 javiercn

I know you said you removed the obj folders everywhere, which is good, but it is surprising that this fixes the issue in a simple repro project, but not in your real project. I just tried the full repro in that version (new .NET 7 projects, upgrade assistant on both, add new folder and component etc.) and it worked fine, which seems to confirm your results too.

Is there anything in your real project that does any "fancy" msbuild things, like configuring the IntermediateOutputPath, or even maybe opting in to the new artifacts layout? Are any of your projects multitargeting?

Would it be possible for you to list the file paths involved in your real project? It would be useful to get an idea of where the .sln file is, where all of the .csproj files are, their relationships to each other, etc. It would also be useful to get a list of all of the project.razor.vs.bin files anywhere on the file system, inside your solution directory.

It sounds a lot like the issue would be fixed by https://github.com/dotnet/razor/pull/9601, which has just shipped in Visual Studio 17.9 Preview 2, however it also should have been fixed by cleaning out all of the obj folders, so I can't be fully confident when I say that. If it is possible for you to try the new preview release, it would be very useful to know if the problem is fixed in that version.

davidwengier avatar Dec 13 '23 06:12 davidwengier

I am not doing anything fancy. (multi targeting, intermediateoutputpath etc). I upgraded to Preview 2. The issue persists, IntelliSense doesn't see the components, it also doesn't see all the namespaces. Check the screenshot:

No Namespaces

mayur-ekbote avatar Dec 13 '23 20:12 mayur-ekbote

Thanks for the reply @mayur-ekbote, but unfortunately I'm not sure what the next steps here would be, if the issue only repros in your project, and not in a simple one.

Does the issue get fixed if you open one of the files that is missing from intellisense? Would it be possible for you to list the file paths involved in your real project? It would be useful to get an idea of where the .sln file is, where all of the .csproj files are, their relationships to each other, etc. It would also be useful to get a list of all of the project.razor.vs.bin files anywhere on the file system, inside your solution directory.

If you'd be willing, it would be most useful if you can zip up your project and email it to me (david.wengier at microsoft.com) so I could see if I can reproduce it on my machine, with the exact setup you have.

davidwengier avatar Dec 18 '23 05:12 davidwengier

It is not possible to share the project (proprietary + large). However, I can share my desktop over a remote zoom/teams session. You can look through any project files you want to figure out the conditions that can reproduce the bug.

mayur-ekbote avatar Dec 18 '23 07:12 mayur-ekbote

Any update on this? The latest VS updates don't fix this

mayur-ekbote avatar Jan 16 '24 07:01 mayur-ekbote

@mayur-ekbote , let's work out a time to meet and share screens, you can contact me

phil-allen-msft avatar Jan 18 '24 22:01 phil-allen-msft

Upon inspection of the csproj file, I saw that the following lines were added. I have no idea what triggered this addition and why this razor component was added (it doesn't happen with all malfunctioning razor components)

<ItemGroup>
    <UpToDateCheckInput Remove="Pages\Instruction\Fragments\SymbolLabel.razor" />
  </ItemGroup>
  <ItemGroup>
    <_ContentIncludedByDefault Remove="Pages\Instruction\Fragments\SymbolLabel.razor" />
  </ItemGroup>

mayur-ekbote avatar Jan 30 '24 07:01 mayur-ekbote

I'm creating a new Blazor Server app with components in a shared RCL. I noticed the designer was failing to recognize my components in the RCL, yet the application was running fine.

After deleting the bin and obj folders, the designer started recognizing the components in RCL correctly.

Then, I backed my RCL out of the solution and got the Blazor Server app to build and run stand alone again. After re-adding the RCL and referencing its components, this problem returns: I can run the Blazor Server app, but the designer has errors about missing classes for the shared components.

In summary, steps to reproduce seem to be:

  1. Create new Blazor Server app and run it at least once
  2. Create RCL and some components
  3. Reference these components from the Blazor Server app.
  4. The app runs correctly but the designer is showing errors.

And to fix:

  1. Close visual studio
  2. Delete bin and obj folders from Blazor Server app

zacuke avatar Feb 29 '24 15:02 zacuke

I'm creating a new Blazor Server app with components in a shared RCL. I noticed the designer was failing to recognize my components in the RCL, yet the application was running fine.

@zacuke What version of Visual Studio are you using?

danroth27 avatar Feb 29 '24 16:02 danroth27

Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.9.2

The projects both target .net 8

Output from dotnet --list-sdks: 6.0.419 [C:\Program Files\dotnet\sdk] 8.0.200 [C:\Program Files\dotnet\sdk]

zacuke avatar Feb 29 '24 17:02 zacuke

Is there any update on this? I am unable to create debug points in the file. Not that I can't create debug points at all. But I can create debug points till a line in the file and then I can't! Check the video:

https://github.com/dotnet/razor/assets/40038634/e0fc263c-d54e-4447-bc56-79a98ac0d01b

mayur-ekbote avatar Mar 18 '24 05:03 mayur-ekbote

@mayur-ekbote The issue you're describing does look like a bug, but it seems different from this one. I recommend opening a Visual Studio feedback ticket with detailed steps on how to reproduce the problem you are seeing.

danroth27 avatar Mar 18 '24 20:03 danroth27