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



The information in this article applies to:

  • Microsoft .NET Framework 1.0
  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual Basic .NET (2003)
  • Microsoft .NET Framework 1.1
  • Microsoft Visual C# .NET (2003)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

To create a COM DLL, follow these steps:
  1. In Microsoft Visual Basic 6.0, create a new Microsoft ActiveX DLL project.
  2. 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
  3. On the File menu, click Make Project1.dll.

To call a COM component, follow these steps:
  1. Open Microsoft Visual Studio .NET.
  2. On the File menu, point to New, and then click Project.
  3. Under Project Types, click to select Visual Basic Projects or Visual C# Projects.
  4. Under Templates, click to select Console Application. Click OK.
  5. In Solution Explorer, right-click Reference, and then click Add Reference.
  6. On the COM Properties page, click Browse.
  7. Locate the new Project1.dll file, and then click Open. Click OK.
  8. 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("Project1.Class1");
    object myObj;
    
    myObj = Activator.CreateInstance(objClassType);
    objClassType.InvokeMember("test",System.Reflection.BindingFlags.InvokeMethod ,null,myObj,null);
    
  9. On the Debug menu, click Start to run the application.

    You may receive the exception in the "Symptoms" section of this article.

REFERENCES

For more information about COM Interop, visit the following MSDN Web site:

COM Interop
http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconcominteroperability.asp

Modification Type:MinorLast Reviewed:9/13/2005
Keywords:kbvs2002sp1sweep kbCOMInterop kbbug KB817057 kbAudDeveloper