Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CodeConverter/CSharp/WinformsConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ private IEnumerable<Assignment> GetAssignmentsFromInitializeComponent(VBSyntax.M
return CreateNameAssignment(maes.Expression.LastOrDefaultDescendant<VBSyntax.IdentifierNameSyntax>());
}
} else if (ShouldReassignProperty(s)){
return CreatePropertyAssignment(s.Left.LastOrDefaultDescendant<VBSyntax.IdentifierNameSyntax>());
var id = s.Left is VBSyntax.IdentifierNameSyntax directId ? directId : s.Left.LastOrDefaultDescendant<VBSyntax.IdentifierNameSyntax>();
if (id == null) return null;
return CreatePropertyAssignment(id);
}

return null;
Expand Down
126 changes: 126 additions & 0 deletions Tests/CSharp/MemberTests/EventMemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,132 @@ private void _dep_SomeEvent(object sender, EventArgs e)
");
}

[Fact]
public async Task Issue1242_WinformsNullRefOnBareIdentifierInInitializeComponentAsync()
{
// Regression test: bare identifier (no Me. prefix) in InitializeComponent caused a NullReferenceException
// in WinformsConversions.CreatePropertyAssignment when s.Left is IdentifierNameSyntax and
// LastOrDefaultDescendant returns null (since DescendantNodes does not include the node itself).
await TestConversionVisualBasicToCSharpAsync(@"Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.CompilerServices

Partial Class BaseForm
Inherits Form
Friend WithEvents BaseButton As Button
End Class

<DesignerGenerated>
Partial Class BaseForm
Inherits System.Windows.Forms.Form

Private Sub InitializeComponent()
BaseButton = New Button()
End Sub
End Class

<DesignerGenerated>
Partial Class Form1
Inherits BaseForm
Private Sub InitializeComponent()
Me.Button1 = New Button()
End Sub
Friend WithEvents Button1 As Button
End Class

Partial Class Form1
Private Sub MultiClickHandler(sender As Object, e As EventArgs) Handles Button1.Click,
BaseButton.Click
End Sub
End Class", @"using System;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using Microsoft.VisualBasic.CompilerServices; // Install-Package Microsoft.VisualBasic

internal partial class BaseForm : Form
{
private Button _BaseButton;

internal virtual Button BaseButton
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return _BaseButton;
}

[MethodImpl(MethodImplOptions.Synchronized)]
set
{
_BaseButton = value;
}
}

public BaseForm()
{
InitializeComponent();
BaseButton = _BaseButton;
}
}

[DesignerGenerated]
internal partial class BaseForm : Form
{

private void InitializeComponent()
{
_BaseButton = new Button();
}
}

[DesignerGenerated]
internal partial class Form1 : BaseForm
{
internal override Button BaseButton
{
[MethodImpl(MethodImplOptions.Synchronized)]
get
{
return base.BaseButton;
}

[MethodImpl(MethodImplOptions.Synchronized)]
set
{
if (base.BaseButton != null)
{
base.BaseButton.Click -= MultiClickHandler;
}

base.BaseButton = value;
if (base.BaseButton != null)
{
base.BaseButton.Click += MultiClickHandler;
}
}
}

public Form1()
{
InitializeComponent();
}
private void InitializeComponent()
{
Button1 = new Button();
Button1.Click += new EventHandler(MultiClickHandler);
}
internal Button Button1;
}

internal partial class Form1
{
private void MultiClickHandler(object sender, EventArgs e)
{
}
}
");
}

[Fact]
public async Task Test_Issue701_MultiLineHandlesSyntaxAsync()
{
Expand Down
70 changes: 35 additions & 35 deletions web/package.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
{
"name": "codeconverter",
"version": "10.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"start": "vite",
"test": "vitest",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint ./src/"
},
"dependencies": {
"@monaco-editor/react": "^4.7.0",
"axios": "^1.15.0",
"bootstrap": "^5.3.8",
"monaco-editor": "^0.55.1",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-router-bootstrap": "^0.26.3",
"react-router-dom": "^7.13.0",
"reactstrap": "^9.2.3"
},
"devDependencies": {
"@types/node": "^22.10.5",
"@types/react": "^19.2.13",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^4.3.4",
"jsdom": "^27.0.1",
"typescript": "~5.7.2",
"vite": "^6.4.2",
"vitest": "^3.2.4"
}
}
{
"name": "codeconverter",
"version": "10.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"start": "vite",
"test": "vitest",
"build": "tsc && vite build",
"preview": "vite preview",
"lint": "eslint ./src/"
},
"dependencies": {
"@monaco-editor/react": "^4.7.0",
"axios": "^1.15.0",
"bootstrap": "^5.3.8",
"monaco-editor": "^0.55.1",
"react": "^19.2.4",
"react-dom": "^19.2.4",
"react-router-bootstrap": "^0.26.3",
"react-router-dom": "^7.13.0",
"reactstrap": "^9.2.3"
},
"devDependencies": {
"@types/node": "^22.10.5",
"@types/react": "^19.2.13",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^4.3.4",
"jsdom": "^27.0.1",
"typescript": "~5.7.2",
"vite": "^6.4.2",
"vitest": "^3.2.4"
}
}
Loading