VisualStudio 2022 17.4.1 Throws the namespace" is a reserved word and cannot be used in implicit expressions. An explicit expression ("@()") must be used." build error in my _ViewImports.cshtml file.

Ajay Krishnan 1 Reputation point
2022-11-24T05:11:27.307+00:00

I have upgraded my Razor project to .netStandard2.1 to .net 6 after that I'm getting "namespace is a reserved word and cannot be used in implicit expressions. An explicit expression ("@()") must be used." build error in my _ViewImports.cshtml file. Same project doesn't throw any error in VisualStudio 2019 16.11.21 version but getting this build error in VisualStudio 2022 17.4.1

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,384 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
37,669 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Zhi Lv - MSFT 32,096 Reputation points Microsoft Vendor
    2022-11-25T02:58:42.193+00:00

    Hi @Ajay Krishnan ,

    264055-image.png

    As we discuss, the issue relates the "Microsoft.AspNetCore.MVC" package, this package is compatible with netStandard2.1 but not apply to .Net 6.
    So, after uninstalling the "Microsoft.AspNetCore.MVC" package, the application works.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion

    0 comments No comments