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

[ Microsoft.DotNet.ILCompiler ] "COM Interop is not supported on this platform" exception after updating to new version of package #399

Closed
FoggyFinder opened this issue Nov 28, 2020 · 8 comments
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@FoggyFinder
Copy link

The same issue as a previous one but now with MCVE. Well, not entirely but at least it's a runnable project.

Didn't change anything except

<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="1.0.0-alpha-*" />

->

<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" />

StackTrace

Unhandled Exception: System.PlatformNotSupportedException: COM Interop is not supported on this platform.
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ConvertManagedComInterfaceToNative(Object) + 0x42
   at Avalonia.Win32.Interop.UnmanagedMethods.RegisterDragDrop(IntPtr, IDropTarget) + 0x46
   at Avalonia.Win32.OleContext.RegisterDragDrop(IPlatformHandle, IDropTarget) + 0x68
   at Avalonia.Win32.WindowImpl.CreateDropTarget() + 0x43
   at Avalonia.Controls.TopLevel..ctor(ITopLevelImpl, IAvaloniaDependencyResolver) + 0x1ac
   at Avalonia.Controls.WindowBase..ctor(IWindowBaseImpl, IAvaloniaDependencyResolver) + 0x24
   at Avalonia.Controls.Window..ctor(IWindowImpl) + 0x62
   at Views.MainWindow..ctor() + 0x35
   at [email protected](Unit) + 0x1c
   at Gjallarhorn.Avalonia.SingleView`5.Run(FSharpFunc`2) + 0x41
   at Gjallarhorn.Avalonia.SingleView`5.Gjallarhorn-Bindable-Framework-INavigator`3-Run(ApplicationCore`3, FSharpFunc`2) + 0xe
   at [email protected](FSharpFunc`2) + 0x26
   at App.main(String[]) + 0xd3
   at CoreRtAvaloniaMCVE!<BaseAddress>+0x10d217f

Repo with MCVE:

CoreRtAvaloniaMCVE

@jkotas jkotas added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Nov 28, 2020
@jkotas
Copy link
Member

jkotas commented Nov 28, 2020

Duplicate of #306

May also get addressed by AvaloniaUI/Avalonia#4971. cc @kekekeks @jkoritzinsky

@kekekeks
Copy link

It's planned to replace all of Avalonia's COM interop with microcom, but I can't guarantee that it will be in 0.10.0 release, probably in 0.10.1-0.10.5 timeframe

@FoggyFinder
Copy link
Author

Duplicate of #306

@jkotas I doubt. Why then it works with CoreRt-1-*?

@jkotas
Copy link
Member

jkotas commented Nov 28, 2020

COM interop has not been supported by CoreRT so far.

I suspect that it worked for you because of some second order effect, e.g. old version of Avalonia that did not have DragAndDrop support.

@FoggyFinder
Copy link
Author

I suspect that it worked for you because of some second order effect, e.g. old version of Avalonia that did not have DragAndDrop support.

No, it's not the case. The only line that was changed is

<PackageReference Include="Microsoft.DotNet.ILCompiler" Version="6.0.0-*" />

nothing more. You can check it by yourself if you run the sample.

@FoggyFinder
Copy link
Author

Diff for dependencies:

https://www.diffchecker.com/cWLTuNsl

I see nothing suspicious

@jkotas
Copy link
Member

jkotas commented Nov 29, 2020

Thank you for providing a repro. This seems to be side-effect of bug fix #266 .

Before this fix, the apartment state was not set correctly and drap&drop registration was silently failing due to this early out: https://github.com/AvaloniaUI/Avalonia/blob/0f65fadfd10d4c4544670b8a63d9e7638c9704c1/src/Windows/Avalonia.Win32/OleContext.cs#L39

After this fix, the apartment state is set correctly and drag&drop registration is failing with this exception.

You can work around this by deleting [<STAThread>] in your app.fs. It will make the apartment unset like before the fix #266 and your app will work as before.

@FoggyFinder
Copy link
Author

Yay. Thank you. Fantastic - it works.

@jkotas jkotas closed this as completed Nov 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

3 participants