fluentui-blazor icon indicating copy to clipboard operation
fluentui-blazor copied to clipboard

Error publish Static WebApp System.MissingMethodException

Open f4n0 opened this issue 11 months ago • 7 comments

🐛 Bug Report

I've published a static web app, but I get this error:

fail: Microsoft.AspNetCore.Components.Web.ErrorBoundary[0]
      System.MissingMethodException: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.Icons+Regular+Size20+Balloon
         at System.RuntimeType.CreateInstanceMono(Boolean , Boolean )
         at System.RuntimeType.CreateInstanceDefaultCtor(Boolean , Boolean )
         at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
         at System.Activator.CreateInstance(Type type, Boolean nonPublic)
         at System.Activator.CreateInstance(Type type)
         at BlazorGenerator.Utils.BlazorGenExtensions.ToFluentIcon(Type icon)
         at BlazorGenerator.Components.Menu.NavMenu.<BuildRenderTree>b__10_1(RenderTreeBuilder __builder2)
         at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 , RenderFragment )
         at Microsoft.FluentUI.AspNetCore.Components.FluentNavMenu.<BuildRenderTree>b__45_1(RenderTreeBuilder __builder2)
         at Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddContent(Int32 , RenderFragment )
         at Microsoft.AspNetCore.Components.CascadingValue`1[[Microsoft.FluentUI.AspNetCore.Components.FluentNavMenu, Microsoft.FluentUI.AspNetCore.Components, Version=4.4.1.24037, Culture=neutral, PublicKeyToken=null]].Render(RenderTreeBuilder builder)
         at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder , RenderFragment , Exception& )
System.MissingMethodException: Arg_NoDefCTor, Microsoft.FluentUI.AspNetCore.Components.Icons+Regular+Size20+Balloon

💻 Repro or Code Sample

🤔 Expected Behavior

😯 Current Behavior

💁 Possible Solution

🔦 Context

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

f4n0 avatar Mar 01 '24 15:03 f4n0

More context: The error is generated from my code:

    public static Icon? ToFluentIcon(this Type icon)
    {
      return Activator.CreateInstance(icon) as Icon;
    }

And helps me passing types instead of instances (I'm using attribute decorators)

f4n0 avatar Mar 01 '24 15:03 f4n0

By default, when you publish this type of project, Blazor deletes all parts of code not detected as "used". When using reflection, you must specify that this icon/code is used.

See https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options

dvoituron avatar Mar 01 '24 16:03 dvoituron

I've also added <PublishTrimmed>false</PublishTrimmed> and

    
    <TrimmerRootAssembly Include="Microsoft.FluentUI.AspNetCore.Components" />
    <TrimmerRootAssembly Include="Microsoft.FluentUI.AspNetCore.Components.Icons" />
but it keeps failing

f4n0 avatar Mar 01 '24 16:03 f4n0

You say it fails on your (added) code. So you of need to add your own namespace as well

vnbaaij avatar Mar 01 '24 16:03 vnbaaij

also added

f4n0 avatar Mar 01 '24 16:03 f4n0

image and the ones that fails, is a "default" one

and referenced like this:

<FluentNavLink Href="@elem.Route" Match="NavLinkMatch.All" Icon="@(elem.Icon.ToFluentIcon())" IconColor="Color.Accent">@elem.Title</FluentNavLink>

f4n0 avatar Mar 01 '24 16:03 f4n0

Maybe you need to add something like this to your code:

[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(_{your type name}_))]

vnbaaij avatar Mar 02 '24 16:03 vnbaaij

We are using Azure Static Web Apps for hosting the demo site ourselves and the icons etc are working there. See the demo client and demo shared projects here in the repo for the configuration we used. Closing this as it is not actionable from our side.

vnbaaij avatar Mar 04 '24 12:03 vnbaaij