Why does the COM registration generated by the AOT fail, and how do I generate it correctly? #110264
-
When AOT is not used, the following code can register DLLs and perform COM interoperability: [ComVisible(true), Guid("D9BF17DA-DE62-4932-8DAC-14AC6ADBE849")]
public interface IA1 {
int Rnd1();
}
[ComVisible(true), Guid("6047C4FD-1F3A-4E8B-B640-DA44C9D0C761"), ClassInterface(ClassInterfaceType.None)]
public class Lib1 : IA1 {
public int Rnd1() => Random.Shared.Next();
} When I add the last three lines, using <TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableComHosting>true</EnableComHosting>
<IsAotCompatible>True</IsAotCompatible>
<PublishAot>true</PublishAot>
<OptimizationPreference>Size</OptimizationPreference> pubxml: <TargetFramework>net8.0-windows</TargetFramework>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun> How do I correctly generate an AOT COM? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
I probably see the point of this whole thing. COM doesn't support |
Beta Was this translation helpful? Give feedback.
-
It is still possible to write a COM server with Native AOT, but you will have to write the server code manually by implementing |
Beta Was this translation helpful? Give feedback.
EnableComHosting
does not work with Native AOT. TheXxx.comhost.dll
it generates is only designed to work with CoreCLR. I think the SDK should emit an error whenEnableComHosting
is combined withPublishAot
.It is still possible to write a COM server with Native AOT, but you will have to write the server code manually by implementing
IClassFactory
, exportingDllRegisterServer
, etc. like described in COM Server Responsibilities. You will also have to switch your interop to ComWrappers source generation and away fromComImport
(which does not work with Native AOT).@AaronRobinsonMSFT @jkoritzinsky