The generated TypeInference class does not have access to _Imports.razor usings #7445
Description
Describe the bug:
When working with generic components and type inference, the TypeInference
class is not generated in a context where _Imports.razor
usings are available. I'm hitting this when a where
clause needs to be repeated on that class.
Version used:
VS2022 17.0.1
SDK 6.0.100, Microsoft.AspNetCore.App 6.0.0
To reproduce:
Run dotnet build
in https://github.com/Tragetaschen/blazor-type-inference-class-usings-issue
Expected behavior:
None of the files in the project show any errors in VS, so I expect the build to succeed.
Actual behavior:
Building produces the error
…\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\App_razor.g.cs(60,23): error CS0246: The type or namespace name 'MyModel' could not be found (are you missing a using directive or an assembly reference?) […\repro.csproj]
Additional context:
In the App_razor.g.cs, there is a TypeInference
class that does not have any usings within its namespace:
namespace __Blazor.repro.App
{
#line hidden
internal static class TypeInference
{
public static void CreateGeneric_0<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, int __seq0, global::repro.Services.IService<T> __arg0, int __seq1, global::Microsoft.AspNetCore.Components.RenderFragment<T> __arg1)
where T : MyModel
{
__builder.OpenComponent<global::repro.Generic<T>>(seq);
__builder.AddAttribute(__seq0, "Service", __arg0);
__builder.AddAttribute(__seq1, "R", __arg1);
__builder.CloseComponent();
}
}
}
so the MyModel
type in the where
clause is not found.