BUG: “InteropServices.COMException” error message occurs when you pass ByRef Parameters by using late binding
Symptoms
When you call a COM component in Visual Basic .NET, and you use late binding, you may receive the following error message:
An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in microsoft.visualbasic.dll. Additional information: Type mismatch.This behavior occurs when all the following conditions are true: The method that is called is a Public method in the COM component. The method takes a ByRef parameter of type Object.You use late binding to call the COM component.
Resolution
When you run an application, the .NET Framework late binding mechanism tries to pass the ByRef parameters to the COM component as objects. The COM component expects the parameters to be of the type IDispatch. The .NET Framework raises a type mismatch exception. This occurs because the .NET Framework cannot convert the uninitialized objects to the IDispatch type. The early binding signature of the method in the COM component follows:
[id(0x60030000)]HRESULT MyFunc([in, out] IDispatch** var1);

Leave a Reply