Currently you can create .net core application with COM object:
```C#
[Guid("7ce1e40f-760a-4d81-b70b-61108ed15cb4")]
[ComVisible(true)]
public interface IComExampleClass
{
IComModelClass ExampleMethod(string param1, string param2);
}
[Guid("a8436b3f-3657-4a01-a133-fd333a84cb58")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComExampleClass : IComExampleClass
{
public IComModelClass ExampleMethod(string param1, string param2)
{
return new ComModelClass()
{
Result = $"{param1} + {param2}"
};
}
}
[Guid("9f5aeede-ec3e-443d-8ba0-9a9f2a6b9e53")]
[ComVisible(true)]
public interface IComModelClass
{
string Result { get; set; }
}
[Guid("526c6cb5-264d-4629-a894-fff02aeb9ec1")]
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
public class ComModelClass : IComModelClass
{
public string Result { get; set; }
}
But you can't generate tbl file:
```cmd
"c:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7.2 Tools\TlbExp.exe" ComExample.exe /out:ComExample.tlb
you can't register assembly using RegAsm:
c:\Windows\Microsoft.NET\Framework64\v4.0.30319
RegAsm.exe /tlb:ComExample.tlb C:\Users\wnagorsx\source\repos\ConsoleApp1\ConsoleApp1\bin\x64\Debug\net4.7.2\win7-x64\ComExample.exe
How can I register COM objects from .net core and then use it in CPP (existing) application?
I was trying publish application with --self-contained. It doesn't work too.
It looks strange. I can register .Net Standard assembly. If I create .Net Standard Library with above source code and with csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
then RegAsm works good
RegAsm.exe /tlb:C:\[...]\DotnetStandardCom\bin\Debug\netstandard2.0\DotnetStandardCom.tlb C:\[...]\DotnetStandardCom\bin\Debug\netstandard2.0\DotnetStandardCom.dll
Microsoft .NET Framework Assembly Registration Utility version 4.7.3062.0
for Microsoft .NET Framework version 4.7.3062.0
Copyright (C) Microsoft Corporation. All rights reserved.
Types registered successfully
Assembly exported to 'C:\[...]\DotnetStandardCom\bin\Debug\netstandard2.0\DotnetStandardCom.tlb', and the type library was registered successfully
But way I can't register .Net Core assembly?
cc @luqunl @jeffschwMSFT
Will this function be released in .Net Core 3.0?
@wojtpl2 This is an important scenario for .NET Core 3.0. The ability to create and register a managed COM server is something we are going to enable to for .NET Core 3.0. You can track the creation and registration work at https://github.com/dotnet/core-setup/pull/4577 and detailed design document can be found in that review - see COM-activation.md in the PR.
With respect to TLB generation and registration that is still TBD. Basically TlbExp.exe is a very difficult feature to tackle in the .NET Core environment and how or if we plan to add support for that feature is still up for debate.
See https://github.com/dotnet/sdk/pull/2814 for support from the developer side. PR https://github.com/dotnet/core-setup/pull/4577 has been merged.
@AaronRobinsonMSFT thanks!
Most helpful comment
cc @luqunl @jeffschwMSFT