dotnet / dotnet/winforms

Additional Control.Invoke overloads break Visual Basic Code

Open
#10,217 3 comments 0 reactions 1 assignee Claimed by @KlausLoeffelmann View on GitHub
:book: documentation: breaking :boom: regression-release area-VisualBasic priority-2
Dominant language
C#
Stars
4.9k
Forks
1.1k
Avg merge
20h 23m
Merged PRs (30d)
103

Description

### .NET version

.NET 6+

### Did it work in .NET Framework?

Yes

### Did it work in any of the earlier releases of .NET Core or .NET 5+?

.NET 3.1

### Issue description

The new overloads we introduced for `Control.Invoke` breaks Visual Basic code.
This used to be OK before:

```VB
If String.IsNullOrEmpty(Me.Text) Then
>> Me.Invoke(Sub()
>> myDataGridForm.BindableDataGridView.DataSource = myDataSource
>> End Sub)
Return
End If
```

This does no longer work.

![image](https://github.com/dotnet/winforms/assets/9663150/5e7bc689-4b88-402f-9b91-0a24f703c8a2)

The reason is that the Visual Basic compiler automatically creates the expected type for a Lambda. So here, the identifier names represents the actual types, which the compiler automatically generates.

![image](https://github.com/dotnet/winforms/assets/9663150/279b38be-c3d1-486a-b73a-eff430d1ebb0)

To correct this, we need to rewrite it and help the compiler to create the correct type like this (as one solution):

```VB
If String.IsNullOrEmpty(Me.Text) Then
Me.Invoke(New Action(
Sub()
myDataGrid.DataSource = myDataSource
End Sub))
Return
End If
```

### Steps to reproduce

Just try the above discussed code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.