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
489 stars 190 forks source link

Block commenting out a Blazor attribute issues a compile error. #9590

Open Joebeazelman opened 4 years ago

Joebeazelman commented 4 years ago

I tried to comment out the attribute using the razor comment syntax:

<svg id="template" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg"
     viewBox="0 0 651 442" @*@onmousedown="@OnDesignPanelClicked"*@>

Upon execution, it interpreted the commented area as regular Blazor code:

warn: Microsoft.AspNetCore.Components.Server.Circuits.RemoteRenderer[100]
      Unhandled exception rendering component: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@*@onmousedown="@OnDesignPanelClicked"*@' is not a valid attribute name.
System.InvalidOperationException: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@*@onmousedown="@OnDesignPanelClicked"*@' is not a valid attribute name.
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
fail: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost[111]
      Unhandled exception in circuit 'juq2BjFD4RL46PNRh3SetydfRBC3OCZTupfYCpRWu2U'.
System.AggregateException: One or more errors occurred. (InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@*@onmousedown="@OnDesignPanelClicked"*@' is not a valid attribute name.)
 ---> System.InvalidOperationException: InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '@*@onmousedown="@OnDesignPanelClicked"*@' is not a valid attribute name.
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InvokeRenderCompletedCallsAfterUpdateDisplayTask(Task updateDisplayTask, Int32[] updatedComponents)
   --- End of inner exception stack trace ---
info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint '/_blazor'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 417.2702ms 101 
javiercn commented 4 years ago

@Joebeazelman Thanks for contacting us.

@NTaylorMullen @ajaybhargavb Is this supproted in Razor in the middle of a tag?

mkArtakMSFT commented 4 years ago

@NTaylorMullen if this turns out something we need to fix or add support for, we'll consider that for 5.0 timeframe.

Joebeazelman commented 4 years ago

It may well be an existing issue with razor, but I can't think of a single case where block comments are interpreted in other mainstream programming languages.

mrpmorris commented 4 years ago

Seeing as you are inside html the moment you write <, have you tried using html comment notation instead?

TanayParikh commented 2 years ago

Confirmed this still repros.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

datvm commented 11 months ago

This is still an issue in .NET 7, at least for Blazor:

image

Trying to run the above code anyway results in this error:

Failed to execute 'setAttribute' on 'Element': '@* @ref="mnuIdref" *@' is not a valid attribute name.

chsienki commented 4 months ago

@333fred It looks like we're incorrectly parsing here, we find the comment, but wrap it in an attribute: image

That then means when we emit, we're emitting it as an attribute to the component.

image
333fred commented 4 months ago

we find the comment, but wrap it in an attribute

This doesn't surprise me, given that the parser doesn't use leading or trailing trivia; I'm guessing this won't be easy to fix without doing that.

boudinov commented 2 months ago

5 years later this is still an issue, and i wasted few hours on it, learning Blazor. And must be very common issue, as this is how visual studio comments in razor by default... Cmon people