Repository navigation
Description
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:
- Clone https://github.com/jaedan/WinFormsBlazorHybridAOT/
- dotnet publish -r win-x64 --self-contained
- Run executable
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.
Activity
kant2002 commentedon Dec 31, 2022
I think that's related to dotnet/aspnetcore#45580 basically it's issue with how ASP.NET Core code is structure.
you have small issue in original rd.xml
Notice that because
Microsoft.AspNetCore.Components.Routing.Routeris in different assembly thenSystem.Private.CoreLib, you need specify assembly name when reference type name. Don't forget wrap in[]. Sobefore
after
I think you can simplify rd.xml by just writing declaration like this
it's quite possible that you need to root just one class, because others are already detected. I can only recommend guessing here.
jaedan commentedon Dec 31, 2022
Ok, I understand now how to get the rd.xml to find the types and that seems to be working. It doesn't fix the problems - I still get errors that MethodInfo.MakeGenericMethod() is not compatible with AOT compilation, and this must be related to the issue you posted. I think we can close this one and just track it in that issue instead.
Thanks for the help!