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
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.
To work around this bug, perform an early bind instead of a
late bind while you call the COM component.
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.
- Under Project Types, click to select
Visual Basic Projects or Visual C#
Projects.
- Under Templates, click to select
Console Application. Click OK.
- In Solution Explorer, right-click
Reference, and then click Add
Reference.
- On the COM Properties page, click Browse.
- Locate the new Project1.dll file, and then click
Open. Click OK.
- 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);
- On the Debug menu, click
Start to run the application.
You may receive the
exception in the "Symptoms" section of this article.
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
| 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