microsoft / fluentui-blazor

Microsoft Fluent UI Blazor components library. For use with ASP.NET Core Blazor applications
https://www.fluentui-blazor.net
MIT License
3.87k stars 375 forks source link

fix: Message box is not shown in published bundle #1088

Closed pavel-kazutsin-leverx closed 11 months ago

pavel-kazutsin-leverx commented 11 months ago

πŸ› Bug Report

I'm using in my client code message boxes to confirm the user's action and they're working well in debug mode, but in the published bundle not. Stack trace:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.MessageBox
System.MissingMethodException: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.MessageBox
   at System.RuntimeType.CreateInstanceMono(Boolean , Boolean )
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean )
   at System.Activator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider , Type , IComponentRenderMode , Nullable`1 )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] , Int32 , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& , Int32 , Int32 , Int32 , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer , RenderBatchBuilder , Int32 , ArrayRange`1 , ArrayRange`1 )
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder , RenderFragment , Exception& )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

πŸ’» Repro or Code Sample

TemplateConfiguration.razor

@page "/TemplateConfiguration"

@inject IDialogService DialogService

....

@code {

    private async Task ShowConfirmationAsync(string filePath)
    {
        var dialog = await DialogService.ShowConfirmationAsync("Do you confirm the deletion of this template?", "Yes", "No", "Confirmation");
        var result = await dialog.Result;

        if (!result.Cancelled)
            await DeleteTemplateAsync(filePath);
    }
}

MainLayout.razor

@inherits LayoutComponentBase
<FluentMainLayout NavMenuTitle="">
    <Header>
        <LoginDisplay/>
    </Header>
    <Body>
    @Body
    <FluentToastProvider/>
    <FluentDialogProvider/>
    </Body>
    <NavMenuContent>
        <NavigationContent/>
    </NavMenuContent>
</FluentMainLayout>

Program.cs

....

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddFluentUIComponents();

...

await builder.Build().RunAsync();

πŸ€” Expected Behavior

Message box to be shown.

image

😯 Current Behavior

Stack trace:

crit: Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.MessageBox
System.MissingMethodException: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.MessageBox
   at System.RuntimeType.CreateInstanceMono(Boolean , Boolean )
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean , Boolean )
   at System.Activator.CreateInstance(Type , Boolean )
   at System.Activator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider , Type , IComponentRenderMode , Nullable`1 )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] , Int32 , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& , Int32 , Int32 , Int32 , Int32 )
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer , RenderBatchBuilder , Int32 , ArrayRange`1 , ArrayRange`1 )
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder , RenderFragment , Exception& )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

πŸ’ Possible Solution

We have tried to reference MessageBox directly, but it doesn't work too.

 private async Task ShowConfirmationAsync(string filePath)
    {
        var messageBoxDefaultParameters = new DialogParameters<MessageBoxContent>()
        {
            Content = new MessageBoxContent()
            {
                Title = "Confirmation",
                Intent = MessageBoxIntent.Confirmation,
                IconColor = Color.Success,
                Message = "Do you confirm the deletion of this template?",
            },
            DialogType = DialogType.MessageBox,
            PrimaryAction = "Yes",
            SecondaryAction = "No",
        };

        DialogParameters dialogParameters = new()
        {
            DialogType = DialogType.MessageBox,
            Alignment = HorizontalAlignment.Center,
            Title = messageBoxDefaultParameters.Content.Title,
            Modal = string.IsNullOrEmpty(messageBoxDefaultParameters.SecondaryAction),
            ShowDismiss = false,
            PrimaryAction = messageBoxDefaultParameters.PrimaryAction,
            SecondaryAction = messageBoxDefaultParameters.SecondaryAction,
            Width = messageBoxDefaultParameters.Width,
            Height = messageBoxDefaultParameters.Height,
            AriaLabel = $"{messageBoxDefaultParameters.Content.Title}",
            OnDialogResult = messageBoxDefaultParameters.OnDialogResult,
        };

        var messageBox = await DialogService.ShowDialogAsync<MessageBox>(messageBoxDefaultParameters.Content, messageBoxDefaultParameters);

        var result = await messageBox.Result;

        if (!result.Cancelled)
            await DeleteTemplateAsync(filePath);
    }

🌍 Your Environment

vnbaaij commented 11 months ago

Hi,

You're running into an issue with thte trimmer. Please see #1057