Article ID: 814912 - View products that this article applies to.
You may access a Component Object Model (COM) object from managed code and then call a method that has parameters of the type IUnKnown. When you do this by using Microsoft Visual Basic 2005 in Microsoft Visual Studio 2005 or by using Microsoft Visual Basic .NET in Microsoft Visual Studio .NET, you may receive the following error message:
Unhandled exception: System.Runtime.InteropServices.COMException: Type mismatch, occurred at Microsoft.VisualBasic.CompilerServices.LateBinding.LateGet(Object o, Type objType, String name, Object args, String paramnames, Boolean CopyBack) at MyRepro.Module1.Main().
When you use a late-binding mechanism in Visual Studio 2005 or in Visual Studio .NET, the runtime cannot marshal an object that has a value of NOTHING. In Visual Studio 2005 or in Visual Studio .NET, if an object variable contains NOTHING when it is encountered, the object variable is not changed and no instance is automatically created. If the object variable is set to NULL in a program that is written in Microsoft Visual C# .NET, this reproduces the same behavior. In the Microsoft .NET Framework, late binding is implemented by using the InvokeMember method of the Type class.
When you use the late-binding mechanism, you can avoid this behavior if you pass the parameters as UnKnownWrapper to methods that have parameters of type IUnKnown. The UnKnownWrapper constructor initializes a new instance of the UnknownWrapper class with the object that will be wrapped.
The following code sample wraps the invar object, the inoutvar object, and the outvar object that the marshaler must marshal as a COM variant type VT_UNKNOWN.
Steps to reproduce the behaviorIf you have a COM component that is registered on your system, follow these steps:
For more information about default marshaling for objects, visit the following Microsoft Developer Network (MSDN) Web site:
Article ID: 814912 - Last Review: December 3, 2007 - Revision: 2.6