Skip to content

Razor tooling shows false error 'Ambiguous reference between 'NS1.XYZ' and 'NS2.XYZ' #37665

@Eilon

Description

@Eilon

Describe the bug

The Razor Editor Tooling specifically (and not the regular Razor compiler) shows errors in the VS warning list for ambiguous types when a type name for a component exists in more than 1 namespace (even though only one of those types is an actual IComponent).

image

The actual compilation works fine and the app runs, but you get these spurious errors in VS's error list that are distracting and confusing.

The bug seems to be due to this line where it writes out the as-typed tag name:
https://github.com/dotnet/aspnetcore/blob/master/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDesignTimeNodeWriter.cs#L527

It seems to use the TagName instead of the full type name due to the comment at the top of this method:
https://github.com/dotnet/aspnetcore/blob/master/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentDesignTimeNodeWriter.cs#L518-L521

So this code is written in this slightly unusual way to avoid the "unused namespace" error, but can instead cause an ambiguous reference error.

To Reproduce

  1. Clone this repo: https://github.com/Eilon/AddMessageNotificationSample
  2. Open in VS for Windows (VS Code probably shows the same problem, but I think there are some other tooling bug there that will distract from it)
  3. Open the file HelloWorld.razor
  4. Look in the VS Error List and see 4 "ambiguous reference" errors

Further technical details

Microsoft Visual Studio Enterprise 2019 Preview
Version 16.8.0 Preview 2.1
VisualStudio.16.Preview/16.8.0-pre.2.1+30428.66
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Enterprise

Visual C++ 2019   00435-60000-00000-AA935
Microsoft Visual C++ 2019

ASP.NET and Web Tools 2019   16.8.259.4173
ASP.NET and Web Tools 2019

ASP.NET Core Razor Language Services   16.1.0.2042706+bfe936d4db2120e689274a4e0a088f72f424c7cd
Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2019   16.8.259.4173
For additional information, visit https://www.asp.net/

Pre-requisite checklist

  • Steps to reproduce the issue
  • Razor Language Server client logs included.
  • HTML Language Server client logs included

cc @NTaylorMullen

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: DuplicateResolved as a duplicate of another issueStatus: ResolvedbugThis issue describes a behavior which is not expected - a bug.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions