I've created a pretty basic C # DLL, just to test. It looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace CriarDLL
{
[ComVisible(true), InterfaceType(ComInterfaceType.InterfaceIsDual),
Guid("EB331808-BC1C-4B13-9ADC-E634E9102DF4")]
public interface ICalculator
{
int AddNumbers(int x, int y);
int SubNumbers(int x, int y);
int MultNumbers(int x, int y);
double DivNumbers(int x, int y);
}
[ComVisible(true), ClassInterface(ClassInterfaceType.None),
Guid("0BE3D996-63ED-4861-9310-05985C5FFA8E")]
public class Calculator : ICalculator
{
//O construtor não pode conter parametros.
public Calculator()
{
}
public int AddNumbers(int x, int y)
{
return (x + y);
}
public int SubNumbers(int x, int y)
{
return (x - y);
}
public int MultNumbers(int x, int y)
{
return (x * y);
}
public double DivNumbers(int x, int y)
{
return (x / y);
}
}
}
I have done all the processes of marking Register for COM interop
, marquei Sign the assembly
and created a Strong Name Key
, made Assembly Global
(GAC), I created in services and components a COM + Application (which shows the methods that are in the class) .
Then I created another project in C # (Windows Forms) to test the DLL, when I was adding a reference in the COM tab, there was the DLL, but when I clicked OK the following message appeared:
A reference to 'CreateDLL' could not be added. The ActiveX type library 'local \ CreateLL.tlb' was exported from a .NET assembly and can not be added as a reference. Add a reference to the .NET assembly instead.
Does anyone know if I did something wrong? Or is something missing?