user3623874
user3623874

Reputation: 519

Calling COM component from .NET

I have a COM component that I registered on my system and added a reference to in my C# program. When I want to use COM component, I receive exception on this line of code:

ComServerUsedByDotNet.Class1 foo = new ComServerUsedByDotNet.Class1() ;

This is the error that I receive:

System.Runtime.InteropServices.COMException was unhandled Message=Retrieving the COM class factory for component with CLSID {61D54BA2-B9A2-4708-91E5-74C83A025063} failed due to the following error: 80040154. Source=EarlyBoundDotNetClientCS
ErrorCode=-2147221164

So, the error code that I am receiving is -2147221164, and according to http://blogs.msdn.com/b/eldar/archive/2007/04/03/a-lot-of-hresult-codes.aspx , -2147221164 stands for REGDB_E_CLASSNOTREG. Does it mean that my component is not registered? I am pretty sure that I did register it using the Run utility on Windows. If the problem is that I didn't end up registering the COM component, how can I check which COM components have been registered on my system?

Upvotes: 1

Views: 988

Answers (2)

user3623874
user3623874

Reputation: 519

I did register the COM component. I found out that what I needed to was to build the program for 32-bit platform (Project -> Properties -> Build -> Platform Target: x64). The COM component was probably built for 32-bit platform, and .NET application using it should also be built for 32-bit platform.

Upvotes: 2

toadflakz
toadflakz

Reputation: 7944

As David Brabant said, check for the CLSID in the registry to confirm that the COM Server DLL is registered correctly.

If not, you will need to use regsvr32.exe to register the COM server with Windows before it is accessible to .NET.

More info on regsvr32: How to use the Regsvr32 tool and troubleshoot Regsvr32 error messages

Upvotes: 0

Related Questions