Creating COM object written in C#

J

jdyer521

Hello. I have an COM object that was written in C# using ASP.NET.
This
is a COM object. I was able to instantiate this COM object using C++
code. (I hadto import the tlb file at the top of the C++ file.)

Now I need to write JavaScript to access this COM object. The code I
am using is this:
try
{
var myCOMObject = new ActiveXObject("progid");
}

catch (err)
{
}

where progid is the progid from the registry. (It's under
KEY_CLASSES_ROOT\CLSID\(guid)\ProgID.

This is going into the catch block. The error it is getting
(err.number) is -2146827859. I searched the Web, and this error code
means "Automation server can't create object."

What am I doing wrong? I need to create this COM object in
JavaScript.
Many thanks in advance for the help.

Justin
 
N

Nicholas Paldino [.NET/C# MVP]

Justin,

Well, do you have your object registered correctly on the machine?
Where is the assembly located? Did you run regasm on it? How is the COM
object defined?

If I had to guess, I would say that the framework can't find your
assembly (it should probably be registered in the GAC) when trying to create
the COM-callable wrapper.
 
J

jdyer521

Thanks for your reply.

- Yes, I did register the assembly on the machine using regasm. I am
able to instantiate the COM object using C++. I am also able to see it
in the registry.

- Your question about where the assembly was located could have been a
problem. I am using an ASP page that has JavaScript to instantiate the
COM object. The ASP page is: http://localhost/MyDirectory/test.asp.
Just to make sure that wasn't the problem, I copied the DLL to the
same directory where the virtual directory was: c:\inetpub\wwwroot
\MyDirectory.

- It is not in the Global Assembly Cache. Is this a problem? I don't
think this could be causing the problem because when you say:
var blah = new ActiveXObject("progid")
in JavaScript, I think it goes to the registry to look up the progid.
Do you think I need to work on getting the assembly in the GAC?

- You asked how the COM object is defined. It is implementing an
interface like this:

namespace MyNameSpace
{
[Guid("(guid here)"]
public interface MyClass_Interface
{
// method declarations
}

[Guid("guid here"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface MyClass_Events
{
// nothing in here
}

[Guid("guid here"),
[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(MyClass_Interface))]
public class MyClass: MyClass_Interface
{
// private members variables
// method definitions
}
}

I am compiling this in Visual Studio 2005 and then running regasm. I
verified that the COM object was in the registry. I am using the
progid as specified in the registry when I create the ActiveXObject in
JavaScript.

Thanks again for your reply.
 
W

Willy Denoyette [MVP]

Thanks for your reply.

- Yes, I did register the assembly on the machine using regasm. I am
able to instantiate the COM object using C++. I am also able to see it
in the registry.

- Your question about where the assembly was located could have been a
problem. I am using an ASP page that has JavaScript to instantiate the
COM object. The ASP page is: http://localhost/MyDirectory/test.asp.
Just to make sure that wasn't the problem, I copied the DLL to the
same directory where the virtual directory was: c:\inetpub\wwwroot
\MyDirectory.

- It is not in the Global Assembly Cache. Is this a problem? I don't
think this could be causing the problem because when you say:
var blah = new ActiveXObject("progid")
in JavaScript, I think it goes to the registry to look up the progid.
Do you think I need to work on getting the assembly in the GAC?

- You asked how the COM object is defined. It is implementing an
interface like this:

namespace MyNameSpace
{
[Guid("(guid here)"]
public interface MyClass_Interface
{
// method declarations
}

[Guid("guid here"),
InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface MyClass_Events
{
// nothing in here
}

[Guid("guid here"),
[ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(MyClass_Interface))]
public class MyClass: MyClass_Interface
{
// private members variables
// method definitions
}
}

I am compiling this in Visual Studio 2005 and then running regasm. I
verified that the COM object was in the registry. I am using the
progid as specified in the registry when I create the ActiveXObject in
JavaScript.

Thanks again for your reply.



You need to register the assembly using regasm /codebase, or you need to
install the assembly in the GAC.
Being install in the virtual root is of no help, COM is not able to find the
assembly unless it's location is registered using the /codebase option, or
it is found in the GAC.

Willy.
 
J

jdyer521

You need to register the assembly using regasm /codebase, or you need to
install the assembly in the GAC.

I did a regasm with the /codebase option, and I'm still having the
same problem. The constructor to the ActiveXObject is not returning an
instance of the COM object.
 
B

Brian Muth

I find OLEVIEW is a great utility for determining whether a COM object is registered correctly. If you can't instantiate it, it is
installed incorrectly.

HTH

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top