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
507 stars 196 forks source link

Compile error when folder name in Blazor project matches a Project name #11194

Closed scott-david-walker closed 2 weeks ago

scott-david-walker commented 2 weeks ago

Is there an existing issue for this?

Describe the bug

if I have a structure like this . ├── NamespaceIssues.BlazorApp │ └── Shared/ │ └── SomeIrrelevantClass.cs └── NamespaceIssues.Shared/ | └── Contract/ | └── SomeClass

and have a component that takes a list of SomeClass as an argument

Component:


@using global::Shared
<h3>SomeTestComponent</h3>

@code {
    [Parameter]
    public List<SomeClass> SomeClasses { get; set; }
}

Which is called by:

Calling Component:

@page "/counter"
@using global::Shared

<SomeTestComponent SomeClasses="Data"></SomeTestComponent>

@code {
    private List<SomeClass> Data { get; set; } = [];
    protected override void OnInitialized()
    {
        Data.Add(new());
        base.OnInitialized();
    }
}

We end up with multiple compile errors because the compiler appears to be searching the wrong place for the code (searching the Blazor project rather than the shared project).

Error CS0234 : The type or namespace name 'SomeClass' does not exist in the namespace 'NamespaceIssues.Shared' Argument 1: cannot convert from 'System.Collections.Generic.List<Shared.SomeClass>' to 'System.Collections.Generic.List<NamespaceIssues.Shared.SomeClass>'

It can be fixed by changing the folder NamespaceIssues.Shared to a different name but this feels like a workaround rather than a solution.

I've added a full reproduction here: Reproduction

Expected Behavior

I expect that it should find the correct file in the correct namespace even if I have a subfolder in the Blazor project named the same as a class library project.

Steps To Reproduce

I've added a full reproduction here: Reproduction

Exceptions (if any)

No response

.NET Version

8.0.303

Anything else?

No response

jjonescz commented 2 weeks ago

Thanks for taking the time to report this. I can repro the problem in .NET 8.0 but not in .NET 9.0. So closing as fixed.