Message 1 of 4
How to properly register COM components from .NET48 to .NET8.0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This is my .NET4.8 reg method:
cd <cadPath>
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\regasm <MyNET48Program>.dll /tlb
But in NET8.0 tlb can't be created, so I try a simple com demo:
using System.Runtime.InteropServices;
namespace MyCom;
[ComVisible(true)]
[Guid("4FB4A212-AE3B-4D3B-9262-FC2DE2D11098")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface IServer
{
double Add(double a, double b);
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("MyComApp.Server")]
[Guid("648D8C69-C5B2-45AF-9F22-E6AD2E869B20")]
public class Server : IServer
{
public double Add(double a, double b) => a + b;
}
.csproj:
<EnableComHosting>true</EnableComHosting>
then I get one `MyCom.comhost.dll` and move all files(include MyCom.dll) to acad.exe path(D:\Software\AutoCAD\AutoCAD 2026)
In this path reg:
regsvr32 MyCom.comhost.dll
MessageBox say reg success!
In VB6.0 I write a test:
Private Sub Form_Load()
Dim cad As Variant
Set cad = CreateObject("AutoCAD.Application.25")
Dim o As Variant
Set o = cad.GetInterfaceObject("MyComApp.Server")
Dim res As Double
res = o.Add(1.2, 3.4)
End Sub
Error in "cad.GetInterfaceObject("MyComApp.Server"), com components can't be find, C# has same problems.So how can i do?