dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

HeadContent not working with maui with blazor in release #19822

Open WoodyJ007 opened 10 months ago

WoodyJ007 commented 10 months ago

Description

 <BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html">
        <BlazorWebView.RootComponents>
            <RootComponent Selector="head::after" ComponentType="{x:Type blazorweb:HeadOutlet}" />
            <RootComponent Selector="#app" ComponentType="{x:Type local:Main}" />
        </BlazorWebView.RootComponents>
    </BlazorWebView>

this worked fine in 7.0 and HeadContent would correctly be put at the bottom of the head.

This was broken in 8.0 (head content was inserted at the top) https://github.com/dotnet/aspnetcore/issues/51391

Apparently, it was fixed in 8.0.1 (but it's the same issue in Maui).

Since 8.0.1 there is now a new error and Headoutlet throws an error when used in Android Release!

<RootComponent Selector="head::after" ComponentType="{x:Type blazorweb:HeadOutlet}" />
Arg_NoDefCTor, Microsoft.AspNetCore.Components.Web.HeadOutlet
   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 Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider , Type , IComponentRenderMode , Nullable`1 )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateComponent(Type )
   at Microsoft.AspNetCore.Components.RenderTree.WebRenderer.AddRootComponent(Type , String )
   at Microsoft.AspNetCore.Components.WebView.Services.WebViewRenderer.AddRootComponent(Type componentType, String domElementSelector)
   at Microsoft.AspNetCore.Components.WebView.WebViewManager.AttachToPageAsync(String baseUrl, String startUrl)
   at Microsoft.AspNetCore.Components.WebView.IpcReceiver.OnMessageReceivedAsync(PageContext pageContext, String message)
   at Microsoft.AspNetCore.Components.WebView.WebViewManager.<>c__DisplayClass18_0.<<MessageReceived>b__0>d.MoveNext()

Steps to Reproduce

Create a maui app. Use headoutet head::afer on MainPage.xaml and headcontent in a shared MainLayout.razor Debug to android will work fine. Release build to android will throw the error and app fails to load.

Link to public reproduction project repository

No response

Version with bug

8.0.5

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

7.0.101

Affected platforms

Android

Affected platform versions

Android 13

Did you find any workaround?

No response

Relevant log output

Arg_NoDefCTor, Microsoft.AspNetCore.Components.Web.HeadOutlet
   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 Microsoft.AspNetCore.Components.DefaultComponentActivator.CreateInstance(Type )
   at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider , Type , IComponentRenderMode , Nullable`1 )
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateComponent(Type )
   at Microsoft.AspNetCore.Components.RenderTree.WebRenderer.AddRootComponent(Type , String )
   at Microsoft.AspNetCore.Components.WebView.Services.WebViewRenderer.AddRootComponent(Type componentType, String domElementSelector)
   at Microsoft.AspNetCore.Components.WebView.WebViewManager.AttachToPageAsync(String baseUrl, String startUrl)
   at Microsoft.AspNetCore.Components.WebView.IpcReceiver.OnMessageReceivedAsync(PageContext pageContext, String message)
   at Microsoft.AspNetCore.Components.WebView.WebViewManager.<>c__DisplayClass18_0.<<MessageReceived>b__0>d.MoveNext()
WoodyJ007 commented 10 months ago

For anyone having the same problems. The error is removed by turning off trimming and AOT in release. The workaround for the Head output and make it correctly append at the end of the head is by using the