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

TypeLoadException on System.Windows.Forms.Control.SetAcceptDrops in DotNet 8 Preview 4 when Trimming #9155

Closed
fitdev opened this issue May 21, 2023 · 6 comments
Assignees
Labels
area-Trimming priority-2 Work that is important, but not critical for the release
Milestone

Comments

@fitdev
Copy link

fitdev commented May 21, 2023

.NET version

8.0.100-preview.4.23260.5

Did it work in .NET Framework?

No (Not applicable)

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

Yes, it works fine in DotNet 7.

Issue description

During runtime, after I publish my app as a self-contained, trimmed (does not matter the mode) executable, I get the following error even before any form is shown:

System.TypeLoadException
   at System.Windows.Forms.Control.SetAcceptDrops(Boolean)
   at System.Windows.Forms.Control.OnHandleCreated(EventArgs)
   at System.Windows.Forms.Control.WmCreate(Message&)
   at System.Windows.Forms.Control.WndProc(Message&)
   at System.Windows.Forms.ScrollableControl.WndProc(Message&)
   at System.Windows.Forms.ContainerControl.WndProc(Message&)
   at System.Windows.Forms.Application.ParkingWindow.WndProc(Message&)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&)
   at System.Windows.Forms.NativeWindow.Callback(HWND, WM, WPARAM, LPARAM)

Steps to reproduce

  1. Mae a simple WinForms app with a User Control in it on the main form.
  2. Publish with trimming enabled.
@fitdev fitdev added the untriaged The team needs to look at this issue in the next triage label May 21, 2023
@JeremyKuhne JeremyKuhne self-assigned this May 23, 2023
@JeremyKuhne JeremyKuhne removed the untriaged The team needs to look at this issue in the next triage label May 23, 2023
@JeremyKuhne JeremyKuhne added this to the .NET 8.0 milestone May 23, 2023
@JeremyKuhne JeremyKuhne added the priority-2 Work that is important, but not critical for the release label May 23, 2023
@elachlan
Copy link
Contributor

Related: #4649

@merriemcgaw
Copy link
Member

I'll move to .NET 9 since we're not going to close on #4649 in .NET 8

@merriemcgaw merriemcgaw modified the milestones: .NET 8.0, .NET 9.0 Jul 27, 2023
@fitdev
Copy link
Author

fitdev commented Jul 27, 2023

But this is critical! I mean it has worked in DotNet 7 just fine, so it appears to be a regression and a very important one to address. Right now it means no trimming support at all for WinForms, since all but the most trivial apps do make use of User Controls. Is there a chance to address the User Control aspect of it still in time for DotNet 8?

Or at least, perhaps you could advise if it would be possible to still trim the app assembly-wise, by excluding certain assemblies, like the app itself, WinForms assemblies presumably and perhaps some others? And why would it break in DotNet 8 when it was working fine - at least without this complete show-stopper error in DotNet 7?

@cyanfish
Copy link

With .NET 8 you can set TrimMode to partial, which will probably fix it:
https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/trimming-options?pivots=dotnet-8-0#trimming-granularity

@fitdev
Copy link
Author

fitdev commented Nov 26, 2023

Thanks for the suggestion @cyanfish

As a temporary workaround, I instead added: <TrimmerRootAssembly Include="System.Windows.Forms" /> and <TrimmerRootAssembly Include="System.Windows.Forms.Primitives" /> to ItempGroup and that seems to have "fixed" it albeit at a cost of a huge size of WinForms dlls.

Still, proper trimming support for it is a must!

@JeremyKuhne
Copy link
Member

We do not officially support trimming in WinForms as there are a variety of scenarios that do not work and are unlikely to get addressed in the near term. Most notably we have dependencies on BinaryFormatter for OLE (clipboard, etc.). We also cannot do data binding in a trim-safe way.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Trimming priority-2 Work that is important, but not critical for the release
Projects
None yet
Development

No branches or pull requests

5 participants