Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

Attempt at WinForms project part 2 #8071

Closed
teobugslayer opened this issue Apr 4, 2020 · 4 comments
Closed

Attempt at WinForms project part 2 #8071

teobugslayer opened this issue Apr 4, 2020 · 4 comments

Comments

@teobugslayer
Copy link
Contributor

Hi guys,

After the fixes in #7995 (comment) and #7995 (comment) I continued my attempts to run a minimum viable WinForms app. I had to create a minimal rd.xml file:

<Directives>
    <Application>
      <Assembly Name="System.Resources.Extensions"  Dynamic="Required All"/>
      <Assembly Name="System.Windows.Extensions" Dynamic="Required All"/>
    </Application>
</Directives>

which brought me to the next issue. There's an exception thrown from this code from WinForms:

Gdip.GdipLoadImageFromStream(new GPStream(stream), out image))

See https://github.com/dotnet/runtime/blob/master/src/libraries/System.Drawing.Common/src/System/Drawing/Image.Windows.cs#L35

and

internal static partial class Interop
{
    internal static partial class Ole32
    {
 [ComImport,
            Guid("0000000C-0000-0000-C000-000000000046"),
            InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
        internal unsafe interface IStream
....

See https://github.com/dotnet/runtime/blob/master/src/libraries/Common/src/Interop/Windows/Ole32/Interop.IStream.cs#L19

Considering this code talks about interface and Ole32, I assume I hit the missing COM support from #4219 . At any rate, I am opening this issue in case you can think of some smart way to continue forward.

This is my minimal repro project.

@MichalStrehovsky
Copy link
Member

Yes, this is COM. The only workaround that comes to mind is not using the images on the toolstrip, or finding a different way to load the bitmaps. They're currently loaded from a resource stream. Image.FromFile would likely work, for example.

@teobugslayer
Copy link
Contributor Author

Removing the images actually showed the main window (TADA!). However, a second later the app crashed with UIAutomation related exception:

System.Exception: Method '[System.Windows.Forms.Primitives]Interop+UiaCore.UiaRaiseAutomationEvent(IRawElementProviderSimple,UIA)' requires marshalling that is not yet supported by this compiler.
   at Interop.UiaCore.UiaRaiseAutomationEvent(Interop.UiaCore.IRawElementProviderSimple, Interop.UiaCore.UIA) + 0x40
   at System.Windows.Forms.AccessibleObject.RaiseAutomationEvent(Interop.UiaCore.UIA) + 0x39
   at System.Windows.Forms.ToolStripItem.ToolStripItemAccessibleObject.RaiseFocusChanged() + 0x6b
   at System.Windows.Forms.ToolStripItem.Select() + 0x24c
   at System.Windows.Forms.ToolStripItem.HandleMouseEnter(EventArgs) + 0x16b
   at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs, ToolStripItemEventType) + 0x14b
   at System.Windows.Forms.ToolStrip.OnMouseMove(MouseEventArgs) + 0x186
   at System.Windows.Forms.Control.WmMouseMove(Message&) + 0xea
   at System.Windows.Forms.Control.WndProc(Message&) + 0xab5
   at System.Windows.Forms.ScrollableControl.WndProc(Message&) + 0x8a
   at System.Windows.Forms.ToolStrip.WndProc(Message&) + 0x296
   at System.Windows.Forms.MenuStrip.WndProc(Message&) + 0xfa
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&) + 0x31
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&) + 0x141
   at System.Windows.Forms.NativeWindow.Callback(IntPtr, Interop.User32.WM, IntPtr, IntPtr) + 0xee

So ...

@MichalStrehovsky
Copy link
Member

Yeah, accessibility is full of COM. If you're building just something for your personal use, you can probably get rid of the accessibility stuff. Of course, don't ship like that (or have fallback on CoreCLR ready for users with special needs).

I usually look at stack traces like this and try to find an extensibility point somewhere that lets me get rid of the problem. Making your own ToolStripItem descendant that overrides ToolStripItem.CreateAccessibilityInstance might work. There might be more things like this. It depends how dedicated you are. WinForms won't work great without COM.

@teobugslayer
Copy link
Contributor Author

I just wanted to check if there are issues which could be fixed to make WinForms projects (as produced by Visual Studio designer) usable with CoreRT. While the COM issue is unfortunate, at least we now know that if one wants to use WinForms, they need to have a particular rd.xml, so my research was not completely in vain. I really appreciate your help and support - I learned much along the way, so I am happy. Closing this issue now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants