dotnet / corert

This repo contains CoreRT, an experimental .NET Core runtime optimized for AOT (ahead of time compilation) scenarios, with the accompanying compiler toolchain.
http://dot.net
MIT License
2.91k stars 511 forks source link

[Windows Forms] Controls support #7995

Open kant2002 opened 4 years ago

kant2002 commented 4 years ago

Here the summary of controls working in Windows Forms in my limited testing

Common Controls

Containers

Menu & Toolstrip

I can understand that some issues i due to lack of COM support, but some "crash on selection" looks more like CoreRT issue. Anyway, this issue to give visibility for list of supported out-of-box controls.

MichalStrehovsky commented 4 years ago

Great list, thank you for documenting this!

teobugslayer commented 4 years ago

I experimented a bit with the MenuStrip. Unfortunately, I am not a .NET dev, so I hit an impenetrable wall.

On startup, I get a very weird exception (Maybe there's a separate issue with exception generation of CoreRT):

Unhandled exception at 0x00007FF7F1EF5634 in winforms.exe: 0x892BE4EA. occurred

And the following call stack:

FailFast() Unknown S_P_CoreLib_System_Runtime_CalliIntrinsicsCall_5() Unknown S_P_CoreLib_System_Runtime_CalliIntrinsicsCallVoid_3() Unknown S_P_CoreLib_System_Runtime_EHUnhandledExceptionFailFastViaClasslib() Unknown S_P_CoreLib_System_Runtime_EHDispatchEx() Unknown RhThrowEx() Unknown RhpThrowEx() Line 191 Unknown S_P_Interop_Internal_Runtime_CompilerHelpers_RuntimeInteropDataGetStructUnsafeStructSize() Unknown S_P_CoreLib_System_Runtime_InteropServices_MarshalSizeOfHelper() Unknown S_P_CoreLib_System_Runtime_InteropServices_MarshalSizeOf_1() Unknown System_Drawing_Common_System_Drawing_Icon__BmpFrame() Unknown System_Drawing_Common_System_Drawing_IconToBitmap() Unknown System_Windows_Forms_Primitives_System_Windows_Forms_DpiHelperGetBitmapFromIcon() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripScrollButtonget_UpImage() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripScrollButtonCreateControlInstance() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripScrollButton_ctor() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripDropDownMenuget_UpScrollButton() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripDropDownMenuSetDisplayedItems() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripOnLayout() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripDropDownOnLayout() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripDropDownMenuOnLayout() Unknown System_Windows_Forms_System_Windows_Forms_ControlPerformLayout_1() Unknown System_Windows_Forms_System_Windows_Forms_ControlPerformLayout() Unknown System_Windows_Forms_System_Windows_Forms_ControlResumeLayout_0() Unknown System_Windows_Forms_System_Windows_Forms_Layout_LayoutTransactionDispose() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripItemCollectionAddRange() Unknown System_Windows_Forms_System_Windows_Forms_ToolStripItemCollectionAddRange() Unknown winforms_winforms_Form1InitializeComponent() Line 80 Unknown winforms_winforms_Form1_ctor() Line 17 Unknown winforms_winforms_ProgramMain() Line 17 Unknown

I poked a bit blindly around the source code of WInForms and found this very suspicious code:

Marshal.SizeOf(typeof(SafeNativeMethods.BITMAPINFOHEADER))

I blindly tried some permutations inside rd.xml, similar to the following, but frankly, all this could have been latin incantations from the necronomicon, so I assume I did not do it correctly. I always received the same exception regardles of which assemblies I included in the list.

<Assembly Name="System.Drawing.Common"  Dynamic="Required All" />
      <Assembly Name="System.Drawing.Primitives" Dynamic="Required All" />
      <Assembly Name="System.Windows.Forms" Dynamic="Required All" />
      <Assembly Name="mscorlib" Dynamic="Required All" />

I'm leaving this in hope that someone could make sense of the issue.

jkotas commented 4 years ago

Marshal.SizeOf(typeof(SafeNativeMethods.BITMAPINFOHEADER))

You can submit PR to WinForms to change BITMAPINFOHEADER to struct and this line to sizeof(SafeNativeMethods.BITMAPINFOHEADER). It has significantly better performance everywhere, and it is guaranteed to be compatible with CoreRT.

teobugslayer commented 4 years ago

Marshal.SizeOf(typeof(SafeNativeMethods.BITMAPINFOHEADER))

You can submit PR to WinForms to change BITMAPINFOHEADER to struct and this line to sizeof(SafeNativeMethods.BITMAPINFOHEADER). It has significantly better performance everywhere, and it is guaranteed to be compatible with CoreRT.

Even if I do it, how can I verify that this fixes the CoreRT issue? Or, more to the point, if I have built the System.WIndows.Forms and friends assemblies on my machine, how can I reference them from my test CoreRT project?

Suchiman commented 4 years ago

I'd imagine the instructions in https://github.com/dotnet/winforms/blob/master/Documentation/debugging.md should work

teobugslayer commented 4 years ago

I'd imagine the instructions in https://github.com/dotnet/winforms/blob/master/Documentation/debugging.md should work

I suspect the rabbit hole is quite deep :D Challenge accepted! And thank you for the hint!

MichalStrehovsky commented 4 years ago

Marshal.SizeOf(typeof(SafeNativeMethods.BITMAPINFOHEADER))

The fact that the compiler doesn't figure this one out is actually a dumb regression I caused when I was moving things around. Fixing this to use sizeof of a struct is still a very good fix (because it's really just so much faster to use sizeof), but I'm also submitting #8053 that should resolve this too.

jkotas commented 4 years ago

Also, I have submitted the System.Drawing interop improvement as https://github.com/dotnet/runtime/pull/33967