Registering my .net assembly for COM compatibility doesn't reveal my methods

Okay, I'm going crazy. I am trying to make a simple .net assembly visible for use as a COM object, but it does not work. I tried a lot of different applause, but none of them work. So far, the closest I have is the one with the least number of attributes, interfaces, manual registration, etc.

I have vbscript as a test that looks like this:

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

My C # code is as follows:

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

In my project (VS2008), I selected "Make COM Assembly Visible" - adding an attribute to my AssemblyInfo.cs, and I also checked "Register for COM Interop."

I see that ProgId really does not matter (anyway), if I specify the real namespace + class name, I can, however, override it, which I believe is good.

The problem is that my CreateObject is going well, but the Test () method was not found. In fact, if I take a dll and retrieve tlb and expect to see no methods at all.

The error I am getting is this:

C: \ Inetpub \ Wwwroot \ ASPTest \ testrun.vbs (3, 1) Microsoft VBScript runtime error: The object does not support this property or method: "Test"

I would love any feedback, but just to let you know that I tried. I fiddled with Guid and AttributeGuid in the class, defining COMVisible explicitly in the class, and I also tried NOT to register for COM interaction and instead used regasm / codebase / regfile.

One last note - most of my tests revolved around an unsigned assembly, but tried to pinpoint the error that I tried using a strong name / key, but did nothing.

Can someone help me find the problem please?

+3
source share
6 answers

I started from the very beginning and removed anything regarding COM interaction in my project, and then added

 [Guid(...some guid...)] [ComVisible(true)] 

on MyClass, and I added a strong name (I used the project parameter to set it) instead of defining it in AssemblyInfo.cs.

When I compiled the assembly, I copied the files to another place where I did

 regasm MyNamespace.MyClass.dll /codebase /regfile 

Then I started and accepted the registry entry.

This made it work - whenever I make changes, I just recompile and copy the files in the old way (without registering), and then I just do:

 regasm MyNamespace.MyClass.dll /codebase 

... and that these are the changes that I made to MyClass that are immediately displayed in my vbscript and on my asp page.

+1
source

Did I mention that I am running Windows 7 RC 64 bit?

Well, I think this can explain that my VS is not doing it right: http://kbalertz.com/956933/Issues-building-project-assembly.aspx VS seems to be using a 32-bit version of the registry, not 64 bit ...

+2
source

You do not need to define any interface that has methods and implement this interface?

0
source

This works for me:

 using System; using System.Runtime.InteropServices; namespace MyNamespace { [GuidAttribute("8DDE02DF-B31C-4d91-98A7-C64444701985")] [ClassInterface(ClassInterfaceType.AutoDual)] public class clsCOMWraper { public string Test() { return "teststring"; } } } 

The assembly node must be signed.

register with regasm / codebase

0
source

I do not see the constructor for the class. COM Interop needs a default constructor (without any parameters) for it to successfully generate a COM interface.

Try adding a constructor and see if it works.

0
source

check this link, it works fine, I follow it and gives the perfect solution by mistake, for example, "The object does not support this property or method" Code project help

0
source

Source: https://habr.com/ru/post/1346305/


All Articles