Loose coupling of COM in C# or How to avoid COMException 0x80040154
I have a .Net 2 C# application I am developing which uses a VB 6 generated COM DLL. The VB DLL is updated frequently any my application crashes with a System.Ru开发者_开发问答ntime.InteropServices.COMException (0x80040154). The part of the COM DLL I use does not change but the version (and CLSID) will.
The "Specific Version" option for the reference is false. The WrapperTool is tlbimp.
How do I tell my application not to worry about changes in the DLL? Is there any way of checking just the functions I am using?
It is one of the most common COM errors, "Class not registered". It starts at VB6, it has an option to control binary compatibility. I forgot exactly what that looks like, it's been too long. If you don't control this, VB6 is going to create a new COM server with different CLSID values. That requires re-registering the DLL with Regsvr32.exe. And re-generating the interop library with Tlbimp.exe. The latter step is probably the one you missed.
Note that using different CLSID values is a hard requirement for COM, it must be done when the public interface changes. But not when only the implementation changes.
精彩评论