Microsoft KB Archive/327084

= BUG: Visual Basic 6.0 cannot use the .NET method with the ParamArray parameter in Visual Studio .NET =

Article ID: 327084

Article Last Modified on 9/13/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Academic Edition
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Professional Edition

-



This article was previously published under Q327084





SYMPTOMS
Microsoft Visual Basic version 6.0 cannot use the .NET method with the ParamArray parameter in Microsoft Visual Studio .NET. A compile-time error is generated by Visual Basic version 6.0 when it tries to consume the .NET method that has the ByRef ParamArray parameter or the ByRef Structure parameter.

When the .NET method has the ByRef ParamArray parameter, you receive the following error message:

Compile error:

Function or interface marked as restricted, or the function uses an Automation type not supported in Visual Basic

When the .NET method has the ByRef Structure parameter, you receive the following error message:

Compile error:

User-defined type may not be passed ByVal



CAUSE
This problem occurs because Visual Basic version 6.0 does not let the ParamArray parameter and the Structure parameter be passed to the BYVAL value. This problem occurs with a .NET property because a .NET property does not let property parameters be defined by the BYREF value.



RESOLUTION
To work around this problem, you can define the ParamArray parameter and the Structure parameter as BYREF. For a property, you can add a method with the ByRef parameter that assigns the property to the private member.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the &quot;Applies to&quot; section.



Steps to reproduce the problem
 Create a new Visual Basic .NET class library project.

By default, Class1.vb is added.  Put the following code in Class1.vb. Overwrite the existing code.

 Public Class Class1 Dim _res(4) As Byte Public Property res As Byte Get Return _res End Get Set(ByVal Value As Byte) _res = Value End Set End Property

Public Structure s1       Public i As Integer dim j as integer End Structure

Dim _mes As s1   Public Property mes As s1        Get Return _mes End Get Set(ByVal Value As s1) _mes = Value End Set End Property

Public Sub setArrayProp(ByRef Value As Byte) _res = Value End Sub

Public Sub setStructProp(ByRef Value As s1) _mes = Value End Sub

End Class  On the Project Properties menu, click Configuration Properties.

This starts Solution Property Pages.

Click the Build tab, and then click Register for COM Interop. Compile the project.

The Classlibrary1.tlb is generated after the project is compiled.</li> Start Visual Basic version 6.0.</li> Create a standard .exe project.

By default, Form1 is added.</li> Add a button to Form1.

Use the default name for the button. The default name is Command1.</li>  Put the following code in the code window of Form1. Private Sub Command1_Click Dim cls As New Class1 Dim arr As Byte Dim s As s1   arr = cls.res 'cls.res = arr s = cls.mes 'cls.mes = s   Call cls.setArrayProp(arr) Call cls.setStructProp(s) End Sub </li> Add a reference to the Classlibrary1.tlb file that is generated in step 4.</li> Press F5.

The code runs correctly.</li> Uncomment the following two lines, and then run the code again. <ul> cls.res = arr</li> cls.mes = s</li></ul>

You receive the error message that mentioned in the &quot;Symptoms&quot; section.</li></ol>

Additional query words: set property

Keywords: kbtshoot kbbug kbpending kbcominterop kbvs2002sp1sweep KB327084

-

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

© Microsoft Corporation. All rights reserved.