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

False positive RenderFragment warnings #8333

Open wrharper-AASP opened 1 year ago

wrharper-AASP commented 1 year ago

Is there an existing issue for this?

Describe the bug

I am using the Microsoft Teams Toolkit (TeamsFx) with Blazor. Libraries used and cannot be changed due to TeamsFx issues that will follow: image

The issue is with how warnings are being handled with Microsoft.AspNetCore.Components though and doesn't really have to do with TeamsFx from what I can tell.

return
@<div class="scrollingArea1" style="width: 360px; height: calc(100vh - 25px); background-color: @CUSTOMDEFINEDCLASSOBJECT.STRINGVARIABLE; margin-right: -1px; box-shadow: inset -10px 0px 20px -24px rgba(0,0,0,1);">

As you can see in the screenshot below there is a large number of warnings at this line: image

Expected Behavior

no warnings should be popping up.

Steps To Reproduce

Create a RenderFragment based on the code provided above:

return
@<div class="scrollingArea1" style="width: 360px; height: calc(100vh - 25px); background-color: @CUSTOMDEFINEDCLASSOBJECT.STRINGVARIABLE; margin-right: -1px; box-shadow: inset -10px 0px 20px -24px rgba(0,0,0,1);">

If you change anything in the render fragment the warnings will pop up on this line.

Exceptions (if any)

If I remove the @ at the CUSTOMDEFINEDCLASSOBJECT.STRINGVARIABLE and just put back the @, the warnings disappear.

.NET Version

7.0.200

Anything else?

.NET SDK: Version: 7.0.200 Commit: 534117727b

Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.200\

Host: Version: 7.0.3 Architecture: x64 Commit: 0a2bda10e8

.NET SDKs installed: 7.0.200 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download

mkArtakMSFT commented 1 year ago

Thanks for contacting us. Can you confirm that the build actually succeeds even with those warnings shown in VS?

ghost commented 1 year ago

Hi @wrharper-AASP. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

wrharper-AASP commented 1 year ago

It does still work it's just an annoying list that pops up every time you want to hover over the line of code to change code and clogs up the error list which should remain clean. It is some kind of bug with warning detection only.

wrharper-AASP commented 1 year ago

The issue started after I updated to visual studio 17.5.0 which just came out recently.

wrharper-AASP commented 1 year ago

Turns out that if I double click the warning in the error list, it will crash Visual Studio.

mkArtakMSFT commented 1 year ago

Thanks for additional details, @wrharper-AASP. This seems to be a tooling (VS) issue. Will move to appropriate repo to be handled by the relevant team.

davidwengier commented 1 year ago

This presence of the warning at all is related to, and hopefully fixed/fixable by, https://github.com/dotnet/razor/issues/7564 and https://github.com/dotnet/razor/issues/7891

Any C# inside HTML is sent to the HTML language server (and in turn the CSS language server) as the tilde character (~), so that is what error is referring to.

The fact that there are multiple warnings for the same span is a separate issue however

wrharper-AASP commented 1 year ago

I would like to add that this is an even deeper issue with 17.5 in general now. After doing more programming in this new version I have realized that if you get any set of warnings (more than 1) and fix one, then quickly click the 2nd one it can crash sometimes. So, in general it looks like 17.5 has issues with handling warnings even outside of this issue.

davidwengier commented 1 year ago

@wrharper-AASP That definitely sounds like a problem! Would it be possible for you to use the VS feedback system (Help -> Submit Feedback -> Report a Problem) and try to capture a recording of the crash? That will capture a memory dump and other details that will help track down the cause of the crash, as its unlikely that whatever bug you're hitting there is specific to the Razor editor.

davidwengier commented 1 year ago

Putting this back into triage for the multiple diagnostics issue

wrharper-AASP commented 1 year ago

I attached a recording to: https://developercommunity.visualstudio.com/t/175-crashes-and-warning-issues/10294265

davidwengier commented 1 year ago

Thanks @wrharper-AASP, the editor team are working on getting the fix into a servicing release of 17.5. Your repro was crucial to tracking down the issue in the end!!

wrharper-AASP commented 1 year ago

I updated to the latest version today and this issue still seems to exist.