.net – Registering the .net assembly for COM interoperability doesn’t expose the methods

comcom-interopnet

Ok, I'm going crazy. I've been trying to make a simple .net assembly visible to use as a COM object but it's not working. I've been trying a lot of different aproaches but none of them work. So far the closest i've got is the one with the least amount of attributes, interfaces, manually registering etc.

I have a vbscript as a test which looks like this:

Dim o
o = CreateObject("MyNamespace.MyClass")
msgbox o.Test()

My c# code looks like this:

using System;
using System.Runtime.InteropServices;
namespace MyNamespace 
{
  [ProgId("MyNamespace.MyClass")]
  public class MyClass
  {
    public string Test()
    {
       return "teststring";
    }
  }
}

On my project (VS2008) i've selected 'Make assembly COM visible' – which added an attribute to my AssemblyInfo.cs and i also checked 'Register for COM interop'.

I Can see that the ProgId really makes no difference (in my case anyways) – as long as i specify the real namespace+classname, i can however override it which i guess is nice.

The problem is – my CreateObject goes well, but the method Test() can not be found. In fact if i take the dll and extract the tlb and expect that i see no methods at all.

The error i get is this:

C:\inetpub\wwwroot\ASPTest\testrun.vbs(3,
1) Microsoft VBScript runtime error:
Object doesn't support this property
or method: 'Test'

I'd love any feedback, but just to let you know what i've been trying. I've messing around with Guid and AttributeGuid on the class, defining the COMVisible explicitly on the class as well i tried NOT registering for COM interop and instead did regasm /codebase /regfile.

One last note – most my testing has revolved around a non-signed assembly, but trying to pinpoint the error i tried with a strongname/key as well but it didn't do anything.

Can anyone help me find the problem, please?

Best Answer

Did i mention i run Windows 7 RC 64 bit?

Well i think that might explain my VS isn't doing it right: http://kbalertz.com/956933/Issues-building-project-assembly.aspx It seems VS uses the 32bit version of registry and not the 64bit...

Related Topic