This is possible fix for exception thrown when using CoreRT.
Feedback from CoreRT chatroom :
"Btw, you can work around the GetMonitorInfo trouble by making MONITORINFO a struct and passing it either as a pointer or a ref to the GetMonitorInfo method. The compiler can't generate marshaling for classes currently"
Error when using WindowStartupLocation:
Unhandled Exception: System.Exception: Method '[Avalonia.Win32]Avalonia.Win32.Interop.UnmanagedMethods.GetMonitorInfo(native int,MONITORINFO)' requires non-trivial marshalling that is not yet supported by this compiler.
at Avalonia.Win32.Interop.UnmanagedMethods.GetMonitorInfo(IntPtr, UnmanagedMethods.MONITORINFO) + 0x23
at Avalonia.Win32.ScreenImpl.<>c__DisplayClass4_0.<get_AllScreens>b__0(IntPtr, IntPtr, Rect&, IntPtr) + 0x82
at Core2D.Avalonia!<BaseAddress>+0x1475a4b
Error when using menus:
```
Unhandled Exception: System.Exception: Method '[Avalonia.Win32]Avalonia.Win32.Interop.UnmanagedMethods.GetMonitorInfo(native int,MONITORINFO)' requires non-trivial marshalling that is not yet supported by this compiler.
at Avalonia.Win32.Interop.UnmanagedMethods.GetMonitorInfo(IntPtr, UnmanagedMethods.MONITORINFO) + 0x23
at Avalonia.Win32.ScreenImpl.<>c__DisplayClass4_0.
at Core2D.Avalonia!
````
@wieslawsoltes we might as well do a Avalonia.Native port for Windows so that we dont have to deal with marshalling to and from native code :)
@jmacato In long term that would be the best and complete solution, for today we can fix small issues I think :smile:
@wieslawsoltes i definitely agree :smile: so for now we can change MONITORINFO into a struct... can you pop a PR for that bud?
re porting the Avalonia.Win32 API to native: I'd rather keep it in managed code if possible, at least for the windowing. When we add an accessibility layer we'll probably need to add that to Avalonia.Native though.
Avalonia native could probably just supply the monitor info stuff and like you say accessibility. Just where managed code cant be used for whatever reason.
This error also occurs when you mouse over a tooltip
Avalonia.Native is meant for platforms where it's too hard to properly interop with the native code. Cocoa and Qt are good examples. In case of Win32/GTK/X11 and even Wayland it would be easier to maintain managed code base, since they use plain C API.
Regarding MONITORINFO structure: it was probably made a class to initialize cbSize from constructor. I don't see any other reason why it should be a class.
Most helpful comment
Avalonia native could probably just supply the monitor info stuff and like you say accessibility. Just where managed code cant be used for whatever reason.