Select the product you need help with
- Internet Explorer
- Windows Phone
- More products
BUG: You receive a "Type mismatch" error message when you assign a value type variable to a property through COM InterOp in Visual Basic .NET or in Visual Basic 2005
Article ID: 316138 - View products that this article applies to.
This article was previously published under Q316138
When you assign a value to a property of a Component Object Model (COM) object in .NET, you may receive the following error message when you run your application:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in InterOpDemo.exe
Additional information: Type mismatch
The problem occurs if all of the following conditions are true:
Explicitly tell the compiler to use the Let method. For example, you can use code similar to the following to tell the compiler to use Let instead of Set:
Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.
Steps to Reproduce Behavior
If a variant type variable is declared as Public in a class module, Visual Basic implicitly creates Let, Get, and Set accessor methods for this property.
The scenario described in this article also applies to ActiveX controls that are used through COM Interop. The resolution to the problem is the same, but the error message that you receive may be different. When you work with an ActiveX control, the error message returned is a NullReferenceException.
For additional information about a similar scenario that uses an ActiveX control, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/316180/EN-US/ )FIX: System.NullReferenceException Error if You Assign a TreeView Node Tag Property
Article ID: 316138 - Last Review: February 12, 2007 - Revision: 5.1