Register for COM Interoperability

2019-04-02 22:34发布

问题:

I create the following class library in C#:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
//[Guid(<Generate GUID here>)]
public interface _None1
{
    int retval { get; }
}

[ClassInterface(ClassInterfaceType.None)]
//[Guid(<Generate GUID here>)]
[ProgId("Lotr.Test")]
public class None : _None1
{
    public int retval
    {
        get
        { return 1; }
    }
} 

Then I compile it using "Register for COM Interop" and "Make Assembly COM-visible" options. When I try to access it using Excel 2007 VBA on my machine, works fine. However, if I take the .dll and .tlb files to another machine, and then use regasm to register it, the registration happens fine, I am able to reference this in Excel VBA via the tlb, the intellisense works like clockwork, but while execution, VBA runtime gives the following error:
"Runtime error:-2147024894 (80070002)"
"Automation Error: The system cannot find the file specified."

回答1:

You probably need to use /codebase regasm key:

regasm your_assembly_name.dll /codebase


回答2:

I've some things diferents in my COM assemblies:

[InterfaceType(ComInterfaceType.InterfaceIsDual)]
//[Guid(<Generate GUID here>)]
public interface _None1
{
    [DispId(1)]
    int retval { get; }
}

[ClassInterface(ClassInterfaceType.None)]
//[Guid(<Generate GUID here>)]
[ProgId("Lotr.Test")]
public class None : _None1
{
    [STAThread]
    public int retval
    {
        get
        { return 1; }
    }
} 

and I don't know if in a COM interface you can use getter and setter operations... maybe someone knows and help us :)