When a property is passed as a ByRef argument and another argument in the same call contains Await, changes made through the ByRef parameter are not written back to the property.
Version Used:
.NET Framework 4.8 project in Visual Studio 2026 18.4.2
>"C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Current\Bin\Roslyn\vbc.exe" -version
5.4.0-2.26124.8 (99e86a9cadcb983b9607a62b41a415203fb33473)
Also observed with net10.0
$ dotnet --version
10.0.203
$ /home/test/.dotnet/sdk/10.0.203/Roslyn/bincore/vbc -version
5.3.0-2.26219.105 (c23858a6d860abe3ca94f9ac630c3e61b2625664)
Steps to Reproduce:
- Create a Visual Basic console app
- Replace content of
Module1.vb with:
Imports System
Imports System.Threading.Tasks
Class Configuration
Public Property LoginName As String = "Default"
End Class
Module Module1
Sub Main()
LoadConfiguration().Wait()
End Sub
Private Async Function LoadConfiguration() As Task
Dim configuration As New Configuration()
SetIfNotEmpty(configuration.LoginName, Await Task.Run(Function() "New Value"))
Console.WriteLine(configuration.LoginName)
End Function
Private Sub SetIfNotEmpty(ByRef cfgVar As String, value As String)
If Not String.IsNullOrEmpty(value) Then cfgVar = value
End Sub
End Module
- Run program
Expected Behavior:
The program prints "New Value".
The call should behave like passing the awaited value separately:
Dim tmp = Await Task.Run(Function() "New Value")
SetIfNotEmpty(configuration.LoginName, tmp)
Actual Behavior:
The program prints "Default".
The modification made through the ByRef parameter is not written back to configuration.LoginName.
When a property is passed as a
ByRefargument and another argument in the same call containsAwait, changes made through theByRefparameter are not written back to the property.Version Used:
.NET Framework 4.8 project in Visual Studio 2026 18.4.2
Also observed with net10.0
Steps to Reproduce:
Module1.vbwith:Expected Behavior:
The program prints "New Value".
The call should behave like passing the awaited value separately:
Actual Behavior:
The program prints "Default".
The modification made through the
ByRefparameter is not written back toconfiguration.LoginName.