Microsoft KB Archive/817057

= BUG: Unexpected exception when you perform a late bind to call a Component Object Model component that returns a structure =

Article ID: 817057

Article Last Modified on 5/12/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.0
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft .NET Framework 1.1
 * Microsoft Visual C# .NET 2003 Standard Edition

-



SYMPTOMS
In a Microsoft .NET Framework application, when you perform a late bind to call a Component Object Model (COM) component that returns a structure, you may receive the following exception when you run the application:

An unhandled exception of type 'System.ArgumentException' occurred in Mscorlib.dll

Additional information: The method returned a VT_RECORD Variant, which is not supported by Interop.



WORKAROUND
To work around this bug, perform an early bind instead of a late bind while you call the COM component.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
To create a COM DLL, follow these steps:  In Microsoft Visual Basic 6.0, create a new Microsoft ActiveX DLL project.  Copy the following code in the Class1 class: ' Custom structure Public Type struct1 x As Integer End Type

' Public function returning structure Public Function test As struct1 End Function  On the File menu, click Make Project1.dll.

To call a COM component, follow these steps:  Open Microsoft Visual Studio .NET. On the File menu, point to New, and then click Project.</li> Under Project Types, click to select Visual Basic Projects or Visual C# Projects.</li> Under Templates, click to select Console Application. Click OK.</li> In Solution Explorer, right-click Reference, and then click Add Reference.</li> On the COM Properties page, click Browse.</li> Locate the new Project1.dll file, and then click Open. Click OK.</li>  Copy the following code in the Main method.

Visual Basic .NET Code Dim o As Object = New Project1.Class1 Dim s As Project1.struct1

'Calling function 'test' through latebound s = o.test Visual C# .NET Code Type objClassType;

objClassType = Type.GetTypeFromProgID(&quot;Project1.Class1&quot;); object myObj;

myObj = Activator.CreateInstance(objClassType); objClassType.InvokeMember(&quot;test&quot;,System.Reflection.BindingFlags.InvokeMethod ,null,myObj,null); </li> On the Debug menu, click Start to run the application.

You may receive the exception in the &quot;Symptoms&quot; section of this article.</li></ol>

<div class="references_section">