fluentui-blazor
fluentui-blazor copied to clipboard
Error publish Static WebApp System.MissingMethodException
🐛 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]
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)
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
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
You say it fails on your (added) code. So you of need to add your own namespace as well
also added
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>
Maybe you need to add something like this to your code:
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(_{your type name}_))]
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.