Microsoft Knowledge Base Email Alertz

(817057) - 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...

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 817057 - Last Review: May 12, 2007 - Revision: 1.8

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

On This Page

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://msdn2.microsoft.com/en-us/library/6bw51z5z(vs.71).aspx (http://msdn2.microsoft.com/en-us/library/6bw51z5z(vs.71).aspx)

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
Keywords: 
kbvs2002sp1sweep kbcominterop kbbug KB817057
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate