Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NativeAOT] Blazor Hybrid + Windows Forms event bindings after AOT compilation #109888

Closed
dadavadd opened this issue Nov 16, 2024 · 2 comments
Closed

Comments

@dadavadd
Copy link

When using Blazor Hybrid with Windows Forms and NativeAOT compilation, event bindings (@OnClick etc.) stop working although the UI renders correctly. The binds work correctly without NativeAOT.

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
	  <OutputType>WinExe</OutputType>
	  <TargetFramework>net8.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>

	  <PublishAot>true</PublishAot>
	  <_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
	  <CustomResourceTypesSupport>true</CustomResourceTypesSupport>
	  <MetadataUpdaterSupport>false</MetadataUpdaterSupport>
	  <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
	  <JsonSerializerIsReflectionEnabledByDefault>true</JsonSerializerIsReflectionEnabledByDefault>
  </PropertyGroup>

xml files that I used in my project: https://pastebin.com/raw/vhW37bYT
NativeAOT compiling logs: logs.txt

MainForm.cs:

    public partial class MainForm : Form
    {
        private BlazorWebView _blazorWebView;
        public MainForm()
        {
            InitializeComponent();

			var services = new ServiceCollection();
			services.AddWindowsFormsBlazorWebView();

			_blazorWebView = new BlazorWebView
            {
				HostPage = "wwwroot/index.html",
				Services = services.BuildServiceProvider(),
			};

			_blazorWebView.RootComponents.Add<Main>("#app");

			_blazorWebView.Dock = DockStyle.Fill;

			Controls.Add(_blazorWebView);
		}
    }

Main.razor:

@using System.Windows.Forms;



<h1>Hello World!</h1>
<button @onclick="OnClickButton">Hello!</button>

@code {
	private void OnClickButton()
	{
		MessageBox.Show("Hello WOrld!");
	}
}
@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Nov 16, 2024
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@jkotas
Copy link
Member

jkotas commented Nov 16, 2024

Neither WinForms or Blazor are compatible with full trimming and native AOT currently. It is expected that it is not going to work well. You can follow related issues in WinForms and ASP.NET repos: dotnet/winforms#4649, dotnet/aspnetcore#49409, dotnet/aspnetcore#51598

xml files that I used in my project: https://pastebin.com/raw/vhW37bYT

Manual authoring of RdXml files is not supported https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/rd-xml-format.md . It results into poorly performing apps with hard to diagnose functionality issues as you have found. I am sorry we are not going to help you with authoring of RdXml files to make things "work". It is not a time well spent.

@jkotas jkotas closed this as completed Nov 16, 2024
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Nov 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

No branches or pull requests

2 participants