Description
Since .NET 11 Preview 3, WinForms applications compiled with Native AOT result in a very small executable size that fails to execute. This worked correctly in .NET 10 to .NET 11 Preview 2.
While I understand that WinForms is not officially "supported" for Native AOT yet, it was functioning well enough to run even large-scale projects until this preview. I would like to report this regression in hopes of restoring the previous behavior.
Reproduction Steps
dotnet new winforms
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(EnableAOT)' == 'true'">
<PublishAot>true</PublishAot>
<TrimMode>partial</TrimMode>
<_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>
<_SuppressWpfTrimError>true</_SuppressWpfTrimError>
<IsAotCompatible>true</IsAotCompatible>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
<EnableDynamicLoading>true</EnableDynamicLoading>
<IlcDisableReflection>false</IlcDisableReflection>
<OptimizationPreference>Speed</OptimizationPreference>
<StripSymbols>true</StripSymbols>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
</PropertyGroup>
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net11.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
</Project>
dotnet publish -c Release -f net11.0-windows -p:TargetFrameworks=net11.0-windows -p:EnableAOT=true --self-contained false -r win-x64 -o ".\bin\Release\net11.0-windows\publish_aot"
Expected behavior
The output should be a standalone executable of approximately 50MB, and it should correctly display the form when launched. This was the consistent behavior prior to Preview 3.
Actual behavior
The generated executable is extremely small (e.g., only a few hundred KB), which suggests that essential code or metadata is being over-trimmed. It does not launch at all. This same issue occurs with VB.NET winforms projects as well.
Regression?
This worked correctly in .NET 10 to .NET 11 Preview 2.
Known Workarounds
No response
Configuration
Windows 11 Pro x64 26100.8246
.NET 11 SDK Preview 3 CLI
Other information
No response
Description
Since .NET 11 Preview 3, WinForms applications compiled with Native AOT result in a very small executable size that fails to execute. This worked correctly in .NET 10 to .NET 11 Preview 2.
While I understand that WinForms is not officially "supported" for Native AOT yet, it was functioning well enough to run even large-scale projects until this preview. I would like to report this regression in hopes of restoring the previous behavior.
Reproduction Steps
dotnet new winforms
dotnet publish -c Release -f net11.0-windows -p:TargetFrameworks=net11.0-windows -p:EnableAOT=true --self-contained false -r win-x64 -o ".\bin\Release\net11.0-windows\publish_aot"
Expected behavior
The output should be a standalone executable of approximately 50MB, and it should correctly display the form when launched. This was the consistent behavior prior to Preview 3.
Actual behavior
The generated executable is extremely small (e.g., only a few hundred KB), which suggests that essential code or metadata is being over-trimmed. It does not launch at all. This same issue occurs with VB.NET winforms projects as well.
Regression?
This worked correctly in .NET 10 to .NET 11 Preview 2.
Known Workarounds
No response
Configuration
Windows 11 Pro x64 26100.8246
.NET 11 SDK Preview 3 CLI
Other information
No response