Skip to content

When compiling Blazor Hybrid app with NativeAOT, can't root System.Action generic #80075

Closed
@jaedan

Description

@jaedan

Description

I've built a simple WinForms application with a single BlazorWebView and I'm compiling it with NativeAOT. This repo contains code that reproduces the issue: https://github.com/jaedan/WinFormsBlazorHybridAOT/
(Additionally, I've repeated this same example using Photino instead of WinForms here: https://github.com/jaedan/Photino.Blazor.Native and I get the same result)

The applications compile and produce a binary. But when a razor page makes a call back to the main c# code (which triggers the message passing) then the application crashes because it is missing this type:

System.Action`2[Microsoft.AspNetCore.Components.Routing.Router, Microsoft.AspNetCore.Components.EventCallback`1[Microsoft.AspNetCore.Components.Routing.NavigationContext]]

I can't find any way to get that type into rd.xml that actually works. I've tried this:

<Assembly Name="System.Private.CoreLib">
  <Type Name="System.Action`2[Microsoft.AspNetCore.Components.Routing.Router, Microsoft.AspNetCore.Components.EventCallback`1[Microsoft.AspNetCore.Components.Routing.NavigationContext]]" Dynamic="Required All" />
</Assembly>

And that fails as follows:

 Failed to load type 'Microsoft.AspNetCore.Components.Routing.Router' from assembly 'System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'

I've changed the assembly name to Microsoft.AspNetCore.Components, but that just changes it so that it fails to load System.Action instead.

Reproduction Steps

To get crash notifying of missing runtime type:

To get rd.xml problems:

  • Modify rd.xml in the repo to add
    <Assembly Name="System.Private.CoreLib">
      <Type Name="System.Action`2[Microsoft.AspNetCore.Components, Microsoft.AspNetCore.Components.EventCallback`1[Microsoft.AspNetCore.Components.Routing.NavigationContext]]" Dynamic="Required All" />
    </Assembly>
  • dotnet publish -r win-x64 --self-contained

Expected behavior

Need to somehow root System.Action2[Microsoft.AspNetCore.Components, Microsoft.AspNetCore.Components.EventCallback1[Microsoft.AspNetCore.Components.Routing.NavigationContext]] so it stops getting trimmed.

Actual behavior

System.Action2[Microsoft.AspNetCore.Components, Microsoft.AspNetCore.Components.EventCallback1[Microsoft.AspNetCore.Components.Routing.NavigationContext]] gets trimmed

Regression?

I doubt anyone has ever tried this before.

Known Workarounds

Don't use NativeAOT

Configuration

  • .net 7
  • Win11
  • x64
  • Probably not specific to a configuration
  • It's WebView2, so Edge.

Other information

Maybe this is related to #72833? It seems to me like it's trying to resolve the nested types within the parent assembly, but they're clearly in a different assembly so that behavior isn't correct. I'd love to be able to just root types more directly, without putting everything in an <Assembly> tag.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions