I need to create a COM class in .NET8 that needs to be accessible to Excel.
After watching this video, I implemented the following test bed class:
namespace COMTestBedCS
{
[Guid("26a0aa6d-5aba-458f-92b4-b9a30ae0c65c")]
[GeneratedComInterface]
public partial interface ITestBed
{
int GetXPTO();
void SetXPTO(int value);
}
[Guid("3e178f98-522e-4e95-8a9c-6d80dc48b7d5")]
[GeneratedComClass]
public partial class TestBed : ITestBed
{
private int _XPTO = 1024;
public int GetXPTO() => _XPTO;
public void SetXPTO(int value)=>_XPTO = value;
}
}
The project compiles correctly, without errors. However, when I try to reference this test bed in Excel, I get the following error: Can't add a reference to the specified file.
If I try to use regsvr32
, I get the following error:
What am I doing wrong?
For completion sake, here’s the project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
</Project>