corert icon indicating copy to clipboard operation
corert copied to clipboard

COM Support

Open VS-ux opened this issue 5 years ago • 6 comments
trafficstars

HI! So I've seen this repo for a couple of months and it's pretty cool. However, I was wondering when or how COM will be supported. Keep in mind this type of stuff is not my area of expertise so I apologize for any mistakes.

I use Winforms alot and that includes using things such as OpenFileDialog. However, since COM isn't supported, these things don't work. Issue #4219 showed some examples and this sample helped alot. However, when CoreRT'ing and starting the binary it failed. I think it's because I didn't follow step 6 as listed here. I'm unsure what to do on that step. Can somebody guide me through what to do? (I really just need support for MenuStrip, ContextMenuStrip, ToolStrip, and possibly StatusStrip. Thanks

VS-ux avatar Jul 26 '20 06:07 VS-ux

#8143 has discussion about the implementation strategy for ComWrappers in CoreRT. These comments points to components that you may be able to reuse:

https://github.com/dotnet/corert/pull/8143#issuecomment-626201188 https://github.com/dotnet/corert/pull/8143#issuecomment-635051591

MenuStrip, ContextMenuStrip, ToolStrip, and possibly StatusStrip.

You can ignore the "tracker" part of the ComWrappers functionality like RegisterForTrackerSupport for these.

cc @kant2002 @AaronRobinsonMSFT @jkoritzinsky

jkotas avatar Jul 26 '20 19:07 jkotas

Hi! I'm so sorry about the late reply. I was wondering what I would do to implement COM. Do I merge #8143? If I merge it, is there any more work that needs to be done such as setting the ComWrappers object into the Winforms controls? I really apologize if this is really stupid, I don't know much about this area.

VS-ux avatar Jul 28 '20 23:07 VS-ux

@jkotas I'm confused about this aswell. It would improve the value of CoreRT even more.

Joshquinberoani avatar Aug 02 '20 18:08 Joshquinberoani

@Joshquinberoani and @VS-ux I will link to a reply I made in the C#/WinRT repo. I want to make sure expectations are understood about the API in question - it isn't technically needed for COM support and has nothing to do with the built-in COM support. See https://github.com/microsoft/CsWinRT/issues/308#issuecomment-667233254.

AaronRobinsonMSFT avatar Aug 02 '20 21:08 AaronRobinsonMSFT

The built-in COM support in classic .NET runtimes is not AOT friendly.

It is not possible to reliably compute the set of COM interop wrappers that the application is going to need. Well, one can say that it will need everything possible but then the resulting binary is going to be big that defeats the point of runtime optimized for AOT. You can just use CoreCLR as it exists today and it is likely going to work better.

Even if it was possible to reliably compute this set, it is not desirable to build the pre-generation of all COM interop marshaling into the AOT compiler since it is very complex. It is better to delegate both figuring out the set of COM interop wrappers that are required and their generation to an external tool.

ComWrappers helps in two ways:

  • It makes it possible to implement COM interop wrappers efficiently.
  • It makes it possible to inject COM interop wrappers into the system, so that existing components that use e.g. System.Runtime.InteropServices.Marshal APIs or use COM interfaces in P/Invoke signatures continue to work without changes.

jkotas avatar Aug 03 '20 05:08 jkotas

@jkotas Hi! So I downloaded #8143 and built CoreRT (I skipped the tests because they took too long). I then downloaded https://github.com/kant2002/CoreRTWinFormsTestBed/tree/master/WinFormsComInterop, and ran it as is. It worked. Then, I edited the csprojs to use the custom built #8143 CoreRt. I built the project using Cmd and Publish, however I got an error saying could not open "kernal32.lib". I fixed it by using x64 native command prompt. It then built OK. But then, when running the native binary, I got this error:

` ntdll.dll!00007ffab3935854() Unknown KernelBase.dll!00007ffab1452f07() Unknown WindowsFormsApp1.exe!S_P_CoreLib_Interop_mincore__RaiseFailFastException_0() Unknown

WindowsFormsApp1.exe!S_P_CoreLib_Interop_mincore__RaiseFailFastException() Line 49 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_RuntimeExceptionHelpers__FailFast_1() Line 263 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_RuntimeExceptionHelpers__RuntimeFailFast() Line 216 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_Runtime_CalliIntrinsics__Call_5<Int32>() Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_Runtime_CalliIntrinsics__CallVoid_3() Line 17 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_Runtime_EH__UnhandledExceptionFailFastViaClasslib() Line 251 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_Runtime_EH__DispatchEx() Line 711 Unknown WindowsFormsApp1.exe!S_P_CoreLib_System_Runtime_EH__RhThrowEx() Line 617 Unknown WindowsFormsApp1.exe!RhpThrowEx() Line 191 Unknown WindowsFormsApp1.exe!S_P_CoreLib_Internal_Runtime_CompilerHelpers_ThrowHelpers__ThrowTypeLoadException() Line 64 Unknown WindowsFormsApp1.exe!WindowsFormsApp1_WindowsFormsApp1_Program__Main() Unknown WindowsFormsApp1.exe!WindowsFormsApp1__Module___MainMethodWrapper() Unknown WindowsFormsApp1.exe!WindowsFormsApp1__Module___StartupCodeMain() Unknown WindowsFormsApp1.exe!wmain(int argc, wchar_t * * argv) Line 447 C++ [Inline Frame] WindowsFormsApp1.exe!invoke_main() Line 90 C++ WindowsFormsApp1.exe!__scrt_common_main_seh() Line 288 C++ kernel32.dll!00007ffab25730f4() Unknown ntdll.dll!00007ffab38ca33b() Unknown`

Does anybody know a fix to this? Thanks

VS-ux avatar Aug 03 '20 19:08 VS-ux