Skip to content

Nested Editor<T> crashing because of bug in HtmlFieldPrefix.Combine method #53956

Closed
@sal-versij

Description

@sal-versij

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Nesting more than 2 Editor leads to an exception

Expected Behavior

It should work properly and not throw any exception

Steps To Reproduce

https://github.com/sal-versij/NestedEditorTCrash

Just visit the home

Exceptions (if any)

Unhandled exception rendering component: Object reference not set to an instance of an object.
    System.NullReferenceException: Object reference not set to an instance of an object.
       at Microsoft.AspNetCore.Components.Forms.ExpressionFormatter.FormatLambda(LambdaExpression expression, String prefix)
       at Microsoft.AspNetCore.Components.Forms.HtmlFieldPrefix.GetFieldName(LambdaExpression expression)
       at Microsoft.AspNetCore.Components.Forms.InputBase`1.get_NameAttributeValue()
       at Microsoft.AspNetCore.Components.Forms.InputNumber`1.BuildRenderTree(RenderTreeBuilder builder)
       at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)

.NET Version

8.0.100

Anything else?

After searching why this happens, I've found that in HtmlFieldPrefix.cs:23 the loop is not actually looping through the whole _rest because it uses restLength - 1 instead of length - 1 or restLength itself, thus it's ignoring the last element of _rest that is left as the default value in expressions: null, this is propagated to the inputs inside the innermost editor that, when executing GetFieldName(...) throws because _rest of the input contains a null value passed to ExpressionFormatter.FormatLambda that throws NullReferenceException at ExpressionFormatter.cs:41

Metadata

Metadata

Assignees

Labels

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

Type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions