dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.43k stars 987 forks source link

winform aot,Binding operations are not supported when application clipping is enabled #12411

Open aadog opened 3 weeks ago

aadog commented 3 weeks ago

.NET version

.NET SDK: Version: 9.0.100-rc.2.24474.11 Commit: 315e1305db Workload version: 9.0.100-manifests.4872d5d5 MSBuild version: 17.12.0-preview-24473-03+fea15fbd1

运行时环境: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.2.24474.11\

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

net 8

Issue description

build to winform aot mode ,Binding operations are not supported when application clipping is enabled

System.NotSupportedException:“启用应用程序剪裁时不支持绑定操作。”

[异常] System.Windows.Forms.dll!System.Windows.Forms.Control.DataBindings.get()   未知

[异常] xt.dll!xt.Form1.button2_Click_1(object sender, System.EventArgs e) 行 187 C# [异常] System.Windows.Forms.dll!System.Windows.Forms.Button.OnClick(System.EventArgs e) 未知 [异常] System.Windows.Forms.dll!System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs mevent) 未知 [异常] System.Windows.Forms.dll!System.Windows.Forms.Control.WmMouseUp(ref System.Windows.Forms.Message m, System.Windows.Forms.MouseButtons button, int clicks) 未知 [异常] System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) 未知 [异常] System.Windows.Forms.dll!System.Windows.Forms.ButtonBase.WndProc(ref System.Windows.Forms.Message m) 未知 [异常] System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(Windows.Win32.Foundation.HWND hWnd, Windows.Win32.MessageId msg, Windows.Win32.Foundation.WPARAM wparam, Windows.Win32.Foundation.LPARAM lparam) 未知

Steps to reproduce

`

<_SuppressWinFormsTrimError>true
    <PublishAot>true</PublishAot>
    <TrimMode>partial</TrimMode>

`

` textBox1.DataBindings.Add("Text", button1, "Text");

`

Image Image

Olina-Zhang commented 3 weeks ago

@aadog I cannot reproduce this issue in my machine with same .NET 9.0 version: Image

aadog commented 3 weeks ago

@Olina-Zhang *.csproj add `

WinExe net9.0-windows enable True x64 <_SuppressWinFormsTrimError>true true partial

`

aadog commented 3 weeks ago

@Olina-Zhang like he

Image

Olina-Zhang commented 3 weeks ago

Trimming/AOTing WinForms Apps is not supported at this time. When setting it, the form designer cannot be loaded successfully. Related issue: https://github.com/dotnet/winforms/issues/10741.

Image

merriemcgaw commented 2 weeks ago

This is on our radar but there is not a specific schedule to get this working. It is expected that you will get trim warnings with data binding and we need to redesign how databinding and trimming work.

aadog commented 2 weeks ago

What options do we have to not crop parts