开发者

Why can't I access my class through COM?

开发者 https://www.devze.com 2023-01-09 06:36 出处:网络
I have a class library that I have written in C#.net. I want to register it with COM on my 64 bit windows machine so that I can create instances of it using CreateObject() in scripts (javascript, vbsc

I have a class library that I have written in C#.net. I want to register it with COM on my 64 bit windows machine so that I can create instances of it using CreateObject() in scripts (javascript, vbscript, whatever). So I created a setup project. I set the Target Platform of the setup project to x64. The class library project's Target platform is set for AnyCPU. I have created an Custom Action for the installer that does the registrtion of the driver manually and it looks like this...

RegistrationServices regsrv = new RegistrationServices();
if (!regsrv.RegisterAssembly(this.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
{           
   throw new InstallException("Failed To Register driver for COM Interop");
}

I can attach the debugger to this process when it runs and know for certain that this registration occurs successfully.

For some reason, when I try to create an object of the class using CreateObject() it gives me an error saying "Could not create object named ...". However, if I run the script using the cscript.exe in the SysWOW64 folder (the 32bit folder) the object i开发者_StackOverflows created successfully and the rest of my script runs fine. So it appears as though the class is being successfully registered for 32bit but not for 64, OR that my project has a 32 bit dependancy and the 64bit Cscript host process can not create it because of that dependency. My class library does reference one other project that I wrote but it is also set to build for ANY CPU. So it should be good for 32 and 64 bit processes.

Does anyone have any suggestions on how I should track down this 32bit dependency?


Using RegisterAssembly() is very unusual. One thing that could go wrong here is that the installer is running in 32-bit mode. Which would make RegisterAssembly() register the COM server in the wrong registry section.

No need to do this, just set the Register property for the file to COM in the setup project.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号