Skip to content

When using CascadingTypeParameter the global:: is not added to __syntheticArg0 parameter #7157

@xiety

Description

@xiety

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Problem looks like the closed dotnet/aspnetcore#37482 and dotnet/aspnetcore#18757, but dotnet/razor-compiler#34 doesn't fix it in the latest 7.0.100-preview.6.22352.1

Generated code lacks global:: on __syntheticArg0

namespace __Blazor.BlazorBug.App
...
public static void CreateChildComponent_1<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, BlazorBug.GenericClass<T> __syntheticArg0)
...

Produces compilation error:

Error	CS0234	The type or namespace name 'GenericClass<>' does not exist in the namespace '__Blazor.BlazorBug' (are you missing an assembly reference?)

Expected Behavior

Code is generated with global:: on __syntheticArg0

namespace __Blazor.BlazorBug.App
...
public static void CreateChildComponent_1<T>(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder, int seq, global::BlazorBug.GenericClass<T> __syntheticArg0)
...

Steps To Reproduce

Project named BlazorBug

App.razror

<ParentComponent Parameter="new GenericClass<string>()">
    <ChildComponent />
</ParentComponent>

ParentComponent.razor

@typeparam T
@attribute [CascadingTypeParameter(nameof(T))]

@code
{
    [Parameter]
    public GenericClass<T> Parameter { get; set; } = default!;
}

ChildComponent.razor

@typeparam T

GenericClass.cs

namespace BlazorBug;

public class GenericClass<T>
{
}

Exceptions (if any)

No response

.NET Version

7.0.100-preview.6.22352.1

Anything else?

The workaround is to explicitly provide the types or move the GenericClass to a different namespace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions