I am having some performance problems when calling a COM TLB methods from C# using the dynamic
keyword (more information here). Scince I have not had any luck trying to optimise such call I am now looking at a way to convert my TLB library to a native wrapper DLL which I can use directly in my C# project (at this stage I am not even sure that this will help, but instead abstract the performance problems down a layer).
I have used tlbimp.exe
to create a .dll from my COM .tlb file (which is registered) using the VS2013 command prompt and the command
tlbimp F:\SomeDir\GrpSvr.tlb /out:F\SomeDir\GrpSvr.dll
This has produced a managed wrapper C# .dll that I can inspect this using dotPeek. It contains the expected namespace
namespace GRPSVR
{
[TypeLibType(TypeLibTypeFlags.FCanCreate)]
[Guid("FFB54BC4-B15E-11D1-99BC-0000E803C444")]
[ClassInterface(ClassInterfaceType.None)]
[ComImport]
public class GrpCallClass : IGrpCall, GrpCall { /*Expected Methods et al.*/ }
}
and the two interfaces IGrpCall
containing the full template for the generated class and and empty interface GrpCall
. I register this .dll using regasm.exe
and
regasm F:\SomeDir\GrpSvr.dll
Now, I include a reference to this .dll in my project and attempt to instantiate the GrpCallClass
class via
private GRPSVR.GrpCallClass grpSvr = new GRPSVR.GrpCallClass();
But this give the compile time error:
Interop type 'GRPSVR.GrpCallClass' cannot be embedded. Use the applicable interface instead.
So then I try
private GRPSVR.IGrpCall grpSvr = new GRPSVR.GrpCall();
and this works at compile time but at run time I get a
Additional information: Retrieving the COM class factory for component with CLSID {FFB54BC4-B15E-11D1-99BC-0000E803C444} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
But I have registered the .dll.
Will this approach help increase the performance of calling method in the initial COM TLB assembly?
Can someone explain what I am doing wrong and how I can convert my COM .tlb library into a native wrapper .dll?
Thanks for your time.