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

Razor editor doesn't indicate an error for FluentValidator component usage #4645

Open ryanelian opened 4 years ago

ryanelian commented 4 years ago

Describe the bug

error CS0234: The type or namespace name 'FluentValidator' does not exist in the namespace 'Accelist.FluentValidation' (are you missing an assembly reference?) 

This is the offending library: https://github.com/ryanelian/FluentValidation.Blazor

I failed to compile the project with namespace: Accelist.SomethingSomething whenever I use the component in my main (closed source) app project. Like, this file appears with that error:

image

As you can see, the component is actually visible in the IDE:

image

However, my other demo project with the same exact library used builds just fine. (huh) https://github.com/ryanelian/accelist-tech-day-blazor

To Reproduce

Try using the library somewhat in a project. Or simply try compiling the demo project and see if it fails.

EDIT: Try using the library version 1.4.0 in a project with Accelist.Something namespace. 😄

Further technical details

    <TargetFramework>netcoreapp3.1</TargetFramework>
.NET Core SDK (reflecting any global.json):
 Version:   3.1.101
 Commit:    b377529961

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18363
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\3.1.101\

Host (useful for support):
  Version: 3.1.1
  Commit:  a1388f194c

.NET Core SDKs installed:
  2.1.801 [C:\Program Files\dotnet\sdk]
  2.2.401 [C:\Program Files\dotnet\sdk]
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.101 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.All 2.2.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 2.2.6 [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.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 2.2.6 [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.1 [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.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download
Microsoft Visual Studio Enterprise 2019
Version 16.4.4
VisualStudio.16.Release/16.4.4+29728.190
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Enterprise

ASP.NET and Web Tools 2019   16.4.460.23317
ASP.NET and Web Tools 2019

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

Azure App Service Tools v3.0.0   16.4.460.23317
Azure App Service Tools v3.0.0

C# Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.2.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.0.87+gbb515bf382
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Mono Debugging for Visual Studio   16.5.24 (1fafd7e)
Support for debugging Mono processes with Visual Studio.

Node.js Tools   1.5.11023.1 Commit Hash:579896f0984848d17d080c8a1c3ddff98d5ba96f
Adds support for developing and debugging Node.js apps in Visual Studio

NuGet Package Manager   5.4.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Open Command Line   2.4.226
2.4.226

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61912.09160
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.11031.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.4.1-beta4-19614-01+165046097562cfe65b09c2e9a9d8f7cd88526f2c
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6   16.4.0-beta.19556.5+e7597deb7042710a7142bdccabd6f92b0840d354
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Container Tools Extensions (Preview)   1.0
View, manage, and diagnose containers within Visual Studio.

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

VisualStudio.DeviceLog   1.0
Information about my package

VisualStudio.Foo   1.0
Information about my package

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.4.000.309 (d16-4@1d551f9)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.4.0.475 (remotes/origin/d16-4@ac250f5aa)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.4.25 (579ee62)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.1.3.7 (d16-4/d66aed0)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: fd9f379
    Java.Interop: xamarin/java.interop/d16-4@c4e569f
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.28.0@46204c4
    Xamarin.Android Tools: xamarin/xamarin-android-tools/master@9f4ed4b

Xamarin.iOS and Xamarin.Mac SDK   13.10.0.17 (5f802ef)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
ryanelian commented 4 years ago

OK, found the reason for this brainfuckery.

In hindsight, I was asking for this trouble because the component full class path with namespace is FluentValidation.FluentValidator but the project name is Accelist.FluentValidation.Blazor so that's partially my fault. (Republished the package with different namespace)


On the other side apparently, Blazor Class Library generates classes with namespace = the project name silently, which causes this trouble in the first place:

image

What apparently happened (if I'm not mistaken, CMIIW) is that because THAT mysterious _Imports class exists, <FluentValidation.FluentValidator> is treated as Accelist.FluentValidation.FluentValidator in Accelist.SomeProject project namespace. (Ouch...)

However, Blazor .razor designer is blissfully unaware of this mindfuckery, so it happily highlights <FluentValidation.FluentValidator> in the VS IDE without squiggly reds.

image

However, when the .razor gets compiled as C#, all hell broke loose because FluentValidation.FluentValidator is treated as Accelist.FluentValidation.FluentValidator for some reason. (EVEN WHEN @using FluentValidation is added to _Imports.razor AND <FluentValidator> is used!)

image


TL;DR Razor post-compilation C# has bug during namespace resolution.

mkArtakMSFT commented 4 years ago

@NTaylorMullen the issue here is this and below:

However, Blazor .razor designer is blissfully unaware of this mindfuckery, so it happily highlights in the VS IDE without squiggly reds.

allisonchou commented 2 years ago

@ryanelian We've made a significant amount of component and diagnostic improvements in VS2022. Can you confirm whether this issue still repros for you?