I am trying to call a C# COM object from C#.
I created a class library in C# and exported a Type Library using tlbexe.exe. I then registered the type library using regtlibv12.exe. However when I add a reference to my COM object in Visual Studio I get an error saying:
"The Active X type library ... was exported from a .NET assembly and cannot be added as a reference. Add a reference to the .NET assembly instead."
Any assistance would be greatly appreciated.
A 64bit process cannot access the 32bit unmanage code directly. There are 2 domains for COM objects on a 64bit system. One for 64bit processes and one for 32bit processes. They have different registration areas in the registry, so if you regsiter a 32bit only Com object, as far as a 64bit process is concerned is does not exist. Now if you have an assembly that is target for ANY_CPU it can be loaded into either a 64bit or 32bit process by the CLR. However, if ANY_CPU assembly is loaded into a 64bit process, it still is not goign to be able to load any 32bit unmaged code. The solution metioned in the artical uses DCOM and IPC to create an out of process call from 64bit to 32bit code.
You can do the same thing a lot easyer in .Net with WCF. You create a WCF server process that is 32bit that acesses your 32bit managed code. Your 64bit process is a WCF client and makes calls to the 32bit server. You can avoid the network stack by using the Named Pipes protical supported by WCF.
The article mentioned in your comment above applies to unmanaged (or native) code. This is not a problem in .NET provided that you compile the host application as AnyCPU (and I think there may be a problem using x64 assemblies on x86 machines, not sure though). You can ignore the COM interop stuff in your 32-bit DLL (assuming you don't need it for anything else) and just reference it from your 64-bit assembly (just make sure to change the target architecture to AnyCPU).