Skip to content

Blazor inline RenderFragment syntax does not handle EventCallbacks Properly #32227

@davidmilligan

Description

@davidmilligan

Describe the bug

Trying to use EventCallback in an "inline" razor RenderFragment results in a compilation failure. I think this is due to the generated razor cs code calling the wrong AddAttribute override on the builder.

To Reproduce

public class C : ComponentBase
{
    [Parameter] public EventCallback E { get; set; }
}
@code{
    private RenderFragment M() {
       return @<C E=@(() => { }) />;
    }
}

Expected Behavior

Compiles successfully

Actual Behavior

error CS1503: Argument 2: cannot convert from 'bool' to 'Microsoft.AspNetCore.Components.EventCallback'

Further technical details

  • ASP.NET Core version: 5.0.104

Use Case:

Using bUnit to write test cases in .razor files. See: https://bunit.dev/docs/getting-started/writing-tests.html?tabs=xunit#secret-sauce-of-razor-files-tests

This issue was reported in down in the middle of an unrelated thread, but I think it was overlooked, as it wasn't really the main issue: #19640 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-razor.language

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions