Orphaned expression breaks the application
See original GitHub issueDescribe the bug
If inside a Blazor HTML expression there is orphaned symbol or expression it will break the application in result without any kind of error or warning in Visual Studio “Error list”
To Reproduce
for instance :
<img id="@((@context as TreeProxyDataModel).id)" class="eimage" src="/f.png" @onclick="@((e) =>MemberFunction((@context as TreeProxyDataModel).id, e))" />
add “)”, “.” or anything in a random position
<img id="@((@context as TreeProxyDataModel).id)" class="eimage" src="/f.png" ) @onclick="@((e) =>MemberFunction((@context as TreeProxyDataModel).id, e))" />
- No exception, error or warning will be resulted.
Further technical details
- ASP.NET Core version : 3.1
- Include the output of
dotnet --info
.NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4
Runtime Environment: OS Name: Windows OS Version: 6.3.9600 OS Platform: Windows RID: win81-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support): Version: 3.1.0 Commit: 65f04fb6db
.NET Core SDKs installed: 2.0.2 [C:\Program Files\dotnet\sdk] 2.1.700 [C:\Program Files\dotnet\sdk] 2.1.801 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.100-preview2-014569 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0-preview2.19528.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.0-preview2.19525.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and it’s version Visual Studio 2019 Preview 16.5.0 preview 1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (7 by maintainers)
Top GitHub Comments
Thanks for the details, @YordanYanakiev. Given this is a user-error scenario, we’ll look into addressing this during 5.0 timeline, as we’re currently focused on the upcoming Blazor WASM release, which is in May.
I’m not completely certain which scenario you’re referring to. If you mean something like this:
… then we do treat that as HTML. It’s up to the browser whether it allows this combination of tags and attributes. Current browsers choose not to allow an attribute called
)
, hence the runtime error.However if you mean this:
… then yes, that is a Blazor component. But this is not invalid usage. It’s valid and allowed, so the compiler is correct to allow it. Whether it throws or not at runtime depends on the behavior of the
SurveyPrompt
component and whether it chooses to accept a parameter called)
. The one in the template doesn’t allow that, so it throws.However if you wanted, you could change
SurveryPrompt
so that it does accept parameters with any name. For example, inSurveryPrompt.razor
’s@code
block, add this:Now at runtime it won’t throw any more, and instead will log the following to the console:
So now the component does allow a parameter called
)
, and you can implement arbitrary logic to do whatever you want with that parameter.Neither HTML nor
.razor
are XML. XML is something different and more restrictive than either HTML or.razor
.