-
Notifications
You must be signed in to change notification settings - Fork 119
CsWin32 is effectively unusable with trim/AOT #1273
Description
Overview
I suspect this is a known issue, but I figured it was about time to open a tracking issue. The generated code that CsWin32 produces is completely incompatible with trim/AOT. This keeps coming up all over the place as more apps and system components start experimenting with NativeAOT or start migrating to it. This applies not just to the default mode for CsWin32, but also to the blittable mode, as it still generates [ComImport] interfaces, as well as P/Invoke-s with unsupported features for eg. disabled runtime marshalling.
The ask is to make the default mode (optionally opt-in, but not just for the blittable mode) to generate code that is trim/AOT-safe. That is, the generated code must be able to compile (when used) with 0 warnings with these two properties being set:
<PublishAot>true</PublishAot>
<DisableRuntimeMarshalling>true</DisableRuntimeMarshalling>For this to happen, the following things must be true:
- All generated interfaces must be compatible with
ComWrappers- Ie. they should be equivalent to interfaces with
[GeneratedComInterface]on them - All P/Invoke-s should be equivalent to when using
[LibraryImport]
- Ie. they should be equivalent to interfaces with
Until then, CsWin32 is a non-starter with NativeAOT, and we have to tell developers to not use it.
This is a constant source of frustration, because:
- Devs keep trying to use CsWin32 because they mistakenly assume it's trim/AOT-safe. It isn't.
- There are no similar equivalent alternatives.
@jkoritzinsky mentioned it might be possible to update CsWin32 to be built on a shared backend with the COM generators, which is currently work in progress. If so (and if profitable), we should start a conversation/planning to make this happen.