-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
DoneThis issue has been fixedThis issue has been fixedaffected-mediumThis issue impacts approximately half of our customersThis issue impacts approximately half of our customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-component-modelAny feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)feature-renderingFeatures dealing with how blazor renders componentsFeatures dealing with how blazor renders componentsseverity-minorThis label is used by an internal toolThis label is used by an internal tool
Milestone
Description
When passing an Action from one Component to another component if the value is null the code throws the following exception: System.ArgumentException: 'Delegate to an instance method cannot have null 'this'.'
This is caused by the generated code, because it tries to create an instance of the Action delegate instead of just passing the value along as it is:
Component A - Generated Code (A.razor.g.cs)
public partial class A : Microsoft.AspNetCore.Components.ComponentBase
{
protected override void BuildRenderTree(Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder)
{
__builder.OpenComponent<B>(0);
__builder.AddAttribute(1, "When", new System.Action(When));
__builder.CloseComponent();
}
[Parameter]
public Action When { get; set; }
}
Component A (A.razor)
@code{
[Parameter]
public Action When { get; set; }
}
<B When="@When" />
Component B (B.razor)
@code{
[Parameter]
public Action When { get; set; }
}
<span>Empty</span>
Is there a way to override the code generation logic to stop this __builder.AddAttribute(1, "When", new System.Action(When)); and instead do __builder.AddAttribute(1, "When", When);.
stefanloerwald, MarkStega, kovalyovi, koryphaee, mrlife and 7 more
Metadata
Metadata
Assignees
Labels
DoneThis issue has been fixedThis issue has been fixedaffected-mediumThis issue impacts approximately half of our customersThis issue impacts approximately half of our customersarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor ComponentsenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-blazor-component-modelAny feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)Any feature that affects the component model for Blazor (Parameters, Rendering, Lifecycle, etc)feature-renderingFeatures dealing with how blazor renders componentsFeatures dealing with how blazor renders componentsseverity-minorThis label is used by an internal toolThis label is used by an internal tool