razor: [dotnet-sdk-9.0.100-preview.3.24175.24] CS1646 error when building Hawaso

Application Name: Hawaso OS: Windows 10 22H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-preview.3.24175.24 App Source Location Checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2012415

Github Link: https://github.com/VisualAcademy/Hawaso

Verify Scenarios:

  1. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.3.24175.24: Fail
  2. Windows10 21h2 x64 + dotnet-sdk-9.0.100-preview.2.24129.7: Pass
  3. Windows10 21h2 x64 + dotnet-sdk-8.0.202: Pass

Description: CS1646 error shows when we build Hawaso\Hawaso project with dotnet-sdk-9.0.100-preview.3.24175.24

Minimal Repro steps (Demo attached):
Demo.zip

The machine has dotnet-sdk-9.0.100-preview.3.24175.24 installed.

  1. Create default 8.0 ASP .NET Core Web App(Razor Pages).
  2. Create class MyTagHelper.cs:
using Microsoft.AspNetCore.Razor.TagHelpers;
using System;
namespace Demo
{
    [HtmlTargetElement("mytag", Attributes = "myattr")]
    public class MyTagHelper:TagHelper
    {
        [HtmlAttributeName("myattr")]
        public int MyAttr { get; set; }
    }
}
  1. Import taghelper in _ViewImports.cshtml:
@using Demo
@namespace Demo.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Demo
  1. Add the following code in Index.cshtml:
@page
@model IndexModel
@{
    ViewData["Title"] = "Home page";
    int count = 0;
}
<div>
    <mytag myattr='Convert.ToInt32(@count)'></mytag>
</div>

7.Build the app with 9.0.100-preview.3.24175.24 SDK

Expected Result: Build successfully. Actual Result:

Build failed with error: CS1646 Keyword, identifier, or string expected after verbatim specifier: @.

dotnet info:

.NET SDK:
 Version:           9.0.100-preview.3.24175.24
 Commit:            09d6f381e6
 Workload version:  9.0.100-manifests.77bb7ba9
 MSBuild version:   17.10.0-preview-24175-03+89b42a486

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-preview.3.24175.24\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      9.0.0-preview.3.24172.9
  Architecture: x64
  Commit:       9e6ba1f68c

.NET SDKs installed:
  9.0.100-preview.3.24175.24 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-preview.3.24172.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-preview.3.24172.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-preview.3.24175.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

@dotnet-actwx-bot @dotnet/compat

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (18 by maintainers)

Commits related to this issue

Most upvoted comments

@ssugden The @ symbol is not necessary in those expressions, if you remove it, they should work. Otherwise, the fix will be in SDK 8.0.302, it unfortunately did not make it into 8.0.301 (that’s the version installed with VS 17.10.1), as mentioned above. You can also consider temporarily downgrading your SDK to some version before 8.0.300 by adding a global.json file.

@MatthewSteeples the fix for this issue will be in 8.0.302 not 8.0.301.

@MatthewSteeples it’s a bit confusing because this bug exists in both VS and .NET SDK. While the bug fix goes into razor as a single change, it ships in both products and they ship on slightly different schedules.

The VS portion of the fix will impact the design time aspect of razor: errors showing up when editting, the error list in Intellisense mode, etc … The .NET SDK portion is needed to solve the actual build errors.

I am still getting errors with this issue after updating VS2022 to 17.10.1.

For the following razor syntax: =“!@Model.xxxxx” =“(SomeEnum)@Model.xxxxxx”

I get: CS0201 Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement CS1646 Keyword, identifier, or string expected after verbatim specifier: @ CS1002 ; expected CS1525 Invalid expression term ‘’

Hi @jaredpar @MatthewSteeples , Verified it on the latest build 8.0.302, this issue has been fixed.

  1. Windows10 21h2 x64 + dotnet-sdk-8.0.302: Pass
  2. Windows10 21h2 x64 + dotnet-sdk-8.0.301: Fail

Ok, I’ve dug into this a bit more; from what I can tell, all Fuse did here was expose the fact that @ breaks various bits of tag helper rewriting and always has. Runtime code generation was simply smushing things together more than design time was, and I’m guessing there have been many phantom design-time errors for this scenario for a long time. Tag helper rewriting needs to be smarter to handle this case.

@Junjun-zhao this is a real issue, but niche enough that the Razor compiler team don’t consider it a blocker for P3.

@chsienki is this in the razor generator or roslyn?

This should be moved to the Roslyn repo most likely but I don’t have permissions to move it. @jaredpar