2

I've created a C# COM object, and am trying to instantiate it from VBscript (under Windows Scripting Host).

The assembly builds correctly, etc, and RegAsm claims that it is successfully registered. However, whenever I try to instantiate it in a .vbs script, I get:

Error: Could not creawte object named

"MyProgId.blah" Code: 80040154

I'm running Win7 x64 Ultimate, object built for .NET 3.5 with VS2010.

I also tried copying the compiled DLL over to a Win Server 2003 machine, and I get the same results there.

Help.

Also, of note: I can register, but not instantiate, any of our old VB6 COM DLLs. (Yes, I am running the script as administrator.)

Update

Just for grins, I created a test application that uses Type.GetFromProgID() to find and create the object:

Type t = Type.GetTypeFromProgID(progId);

if (t == null)
{
    Console.WriteLine("Couldn't create object.");
}
else
{
    var obj = Activator.CreateInstance(t);

    Console.WriteLine("Successfully created Object: Type is [{0}]", obj);

    Console.WriteLine("Calling method [{0}]\n\n", methodName);

    var result = t.InvokeMember(methodName, BindingFlags.Default | BindingFlags.InvokeMethod, null, obj, null);

    Console.WriteLine("Result: {0}", result);

}

This works correctly. Attempting to create the object from VBscript, however, still fails.

Argh.

Update, the 2nd

After running SysInternals ProcMon, I see quite a few registry queries looking for the progID and guid under HKCU\Software\Classes\..., where there is no mention of the object (when I look in RegEdit). There are quite a few NAME NOT FOUND errors.

I've tried registering with the %windir%\microsoft.net\framework\v4... and framework64 versions of regasm, with no effect.

1
  • If you have Excel/Word installed, see if you can use VBA to figure out if your library appears in the Tools -> References & see if you can instantiate the class from VBA. I dont know if this helps at all. Commented May 18, 2011 at 15:45

3 Answers 3

6

I'm running Win7 x64 Ultimate

That's very relevant to COM issues like these. The error message means that the COM client could not find the registry information for the COM server. The 64-bit version of Windows has two VB-script interpreters, a 64-bit and a 32-bit version. Processes with different bitness have a different view of the registry, a 64-bit client cannot see 32-bit COM servers. And the other way around.

What matters is what version of Regasm.exe you used. There are two, one in C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe, another in Framework64. You by default run the 32-bit version which enters registration info in the 32-bit view of the registry. You should use the 64-bit version from Framework64 instead. Or use both, .NET creates COM servers that can run in both bitnesses.

If you still have trouble then use SysInternals' ProcMon tool to see where the script interpreter is looking for the CLSID key.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the tip. More information added to my post; I'd appreciate some insight.
You are definitely using a 64-bit host. It should find the CLSID registry key in HKLM not HKCU. Although it will try HKCU first. Also make sure that you run Regasm.exe from an elevated command prompt so UAC will allow write access to the HKLM key.
@Hans OK, after many hours of frustration, I decided to build the object on a 32-bit machine and test it there. No joy. Since the 32/64 bitness isn't coming into play, any other ideas?
If it fails on a 32-bit machine then you're down to a basic registration problem. The required keys in the registry are not there. No idea why from your question, ProcMon is the ultimate tool that shows you the host searching the registry for the keys. Yes, drowning in the data is a liability.
I wound up changing the interface type attribute which appears to have solved the problem on the 32-bit machines; still doesn't work on 64, but I'm examining the ProcMon trace to see what I can see. Thanks.
|
2

If you're running a 32-bit interface under a 64-bit OS, you can get around that VBScript error by using the wscript/cscript under \windows\syswow64 (instead of the default under \windows\system32) to run your script. That tripped me up for a day.

Comments

1

I think that it is possible you are looking at a security issue.

Check out this stackoverflow post and see if this solves your issue. Cannot instanciate .Net COM object in classic ASP/VBScript page (Error ASP 0177)

2 Comments

That seems to be specifically related to ASP/IIS permissions; I'm not sure how it applies when I trying to run the script with admin permissions from a command prompt on the machine?
Oh sorry David, I overlooked that. I was thinking an asp vbscript file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.