Microsoft KB Archive/317048

= FIX: SafeArrayTypeMismatchException Error Message When You Invoke a COM Method =

Article ID: 317048

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q317048



SYMPTOMS
When you invoke a method that contains the following signature on a Microsoft Visual Basic 6.0 Component Object Model (COM) component from a managed client Public Function Moo(ByRef Ary As Object) you may receive the following SafeArrayTypeMismatchException error message:

An unhandled exception of type 'System.Runtime.InteropServices.SafeArrayTypeMismatchException' occurred in vbMannagedConApp.exe



CAUSE
The array of managed objects is passed as a SAFEARRAY of VARIANTs, but the unmanaged method expects a SAFEARRAY of IDispatch pointers.



RESOLUTION
To work around this problem, use the following sample code: Sub Main dim objs(9) as Object dim dispArray(9) as System.Runtime.InteropServices.DispatchWrapper dim i as integer

for i = 0 to 9 objs(i) = New Object dispArray(i) = New DispatchWrapper(objs(i)) next

Dim Obj As Project1.Class1Class = New Project1.Class1 Obj.Moo(CType(dispArray, Object)) End Sub



STATUS
This bug was corrected in .NET Framework (2003|1.1).



Steps to Reproduce Behavior
Add a reference to the COM server for a managed application, and then call the Moo method from a managed application as follows: Dim Obj As VB6Server.Class1 = New VB6Server.Class1 Obj.Moo(New Object {New String(&quot;test String&quot;)})

Keywords: kbfix kbcominterop kbpending kbprb KB317048

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.