OYIon / LiveSharp

Public repository for the LiveSharp project
96 stars 4 forks source link

InvalidProgramException with simple object parameter #111

Closed henon closed 3 years ago

henon commented 3 years ago

I have isolated a problem caused by LiveSharp when setting an object typed parameter. Here is the code snippet causing the bug:

This is using MudBlazor

        <MudList Clickable="true">
            @foreach (var page in Pages)
            {
                <MudListItem Text="@(page.Name ?? "null")" @key="@(page?.Id??"null")" Tag="@("hi")"></MudListItem>
            }
        </MudList>

This causes render to fail with an InvalidProgramException only when setting the Tag property and only when LiveSharp is installed. Removing the Tag from the snippet doesn't cause it. It doesn't matter what value you set. I tried Tag="@(page)" or Tag="@null" or even 17 or a string.

The Tag parameter is simply for holding a reference to user data:

        /// <summary>
        /// Use Tag to attach any user data object to the component for your convenience.
        /// </summary>
        [Parameter] public object Tag { get; set; }

This happens with the latest beta version you gave me for testing: LiveSharp.1.6.46-beta.nupkg The server was not even running.

henon commented 3 years ago

I made a repro based on our MudBlazorTemplates for you. This is the error message:

[2021-01-03T18:03:49.608Z] Error: System.InvalidProgramException: Common Language Runtime detected an invalid program.
   at MudBlazor.Blazor.Server.Pages.FetchData.<BuildRenderTree>b__0_0(RenderTreeBuilder __builder2)
   at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 sequence, RenderFragment fragment)
   at MudBlazor.MudContainer.BuildRenderTree(RenderTreeBuilder __builder)
   at Microsoft.AspNetCore.Components.ComponentBase.<.ctor>b__6_0(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

To reproduce:

image

This doesn't even need the Tag property, it just happens on rendering the FetchData page.

ionoy commented 3 years ago

Hello @henon

Sorry for the late reply!

Seems like 1.6.52 fixed this issue. Can I close it?

henon commented 3 years ago

sure, if it still occurs I can reopen.