Registering with the Com Interop option in Visual Studio works but calling Regasm directly doesn't

StackOverflow https://stackoverflow.com/questions/17346459

سؤال

I'm trying to create a 32-bit COM object in .NET 4.0. The consumer of the COM object is a simple JScript.

When I have the checkbox set to true for Visual Studio's "Register for COM interop" setting, everything works fine. I'm able to create the COM object in my JScript and run all my test code.

However, I want to be able to deploy this on a 32-bit machine (which is running .NET 4.0) that does not have Visual Studio on it. So I have a simple install.bat file to register the DLL:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\regasm ComTest.dll /codebase /tlb:ComTest.tlb

As it's a 32 bit assembly, I'm taking care to use the 32 bit regasm.exe. This tells me it registers successfully. I do get a warning for using the /codebase option telling me I might be stepping on existing namespaces, but this won't be a problem in the deployment environment.

But now when I go to create my object in my JScript I get

Could not create object named "COMTest".

Is there something special Visual Studio is doing that's registering it correctly that I'm missing?

I would prefer to not have to sign the assembly, if possible.

هل كانت مفيدة؟

المحلول

I found the issue. (Of course only after I posted to SO...)

The object was registering just fine. The issue was with missing dependencies in the constructor of the COM object.

Moving the initialization code out of the constructor and to an Initialize() method exposed the issue.

Visual Studio worked because of the directory it was running in.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top