Search code examples
c#.netexceptioncomcom-interop

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?


Solution

  • 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.