Copying the value of 'ByRef' parameter '<parametername>' back to the matching argument narrows from type '<typename1>' to type '<typename2>'

 

Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

A procedure is called with an argument that widens to the corresponding parameter type, and the conversion from the parameter to the argument is narrowing.

When you define a class or structure, you can define one or more conversion operators to convert that class or structure type to other types. You can also define reverse conversion operators to convert those other types back to your class or structure type. When you use your class or structure type in a procedure call, Visual Basic can use these conversion operators to convert the type of an argument to the type of its corresponding parameter.

If you pass the argument ByRef, Visual Basic sometimes copies the argument value into a local variable in the procedure instead of passing a reference. In such a case, when the procedure returns, Visual Basic must then copy the local variable value back into the argument in the calling code.

If a ByRef argument value is copied into the procedure and the argument and parameter are of the same type, no conversion is necessary. But if the types are different, Visual Basic must convert in both directions. If one of the types is your class or structure type, Visual Basic must convert it both to and from the other type. If one of these conversions is widening, the reverse conversion might be narrowing.

Error ID: BC32053

To correct this error

  • If possible, use a calling argument of the same type as the procedure parameter, so Visual Basic does not need to do any conversion.

  • If you need to call the procedure with an argument type different from the parameter type but do not need to return a value into the calling argument, define the parameter to be ByVal instead of ByRef.

  • If you need to return a value into the calling argument, define the reverse conversion operator as Widening, if possible.

Procedures
Procedure Parameters and Arguments
Passing Arguments by Value and by Reference
Operator Procedures
Operator Statement
How to: Define an Operator
How to: Define a Conversion Operator
Type Conversions in Visual Basic
Widening and Narrowing Conversions

Show: