Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VB -> C#: Cannot convert ForEachBlockSyntax #601

Closed
docfresh opened this issue Aug 1, 2020 · 5 comments
Closed

VB -> C#: Cannot convert ForEachBlockSyntax #601

docfresh opened this issue Aug 1, 2020 · 5 comments
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@docfresh
Copy link

docfresh commented Aug 1, 2020

Ran into this after conversion.

Input code

Public Sub PopulateFormWinListAndOrderTotal(ByVal frm As frmNewInvoice)
    Dim sngOrderTotal As Single
    frm.lstWindows.Items.Clear()
    For Each Win In WinOrd.colWindows
        WinModel.Populate(Win.GetWinStyleID())

        'if part of a bay or bow do not include window as part of order total since its already figured for in the bay or bow
        If Win.strSuperType <> "BB" Then
            sngOrderTotal = sngOrderTotal + (Win.GetTotalPrice() * Win.GetWinQty())
            frm.lstWindows.Items.Add(New Mylist(WinModel.GetWinAbbreviation() & " " & Win.GetWidth() & " x " & Win.GetHeight() & " (" & Win.GetWinQty() & ")", Win.GetInvItemID()))
        Else
            frm.lstWindows.Items.Add(New Mylist("**" & WinModel.GetWinAbbreviation() & " " & Win.GetWidth() & " x " & Win.GetHeight() & " (" & Win.GetWinQty() & ")", Win.GetInvItemID()))
        End If


    Next
    frm.lblOrderTotalRetail.Text = sngOrderTotal
    frm.lblOrderTotalDealer.Text = (sngOrderTotal * WinOrd.GetSoldMultiplier())
End Sub

Erroneous output

#error Cannot convert ForEachBlockSyntax - see comment for details

/* Cannot convert ForEachBlockSyntax, System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.IdentifierNameSyntax'.
at ICSharpCode.CodeConverter.CSharp.MethodBodyExecutableStatementVisitor.d__61.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.CodeConverter.CSharp.HoistedNodeStateVisitor.d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ICSharpCode.CodeConverter.CSharp.CommentConvertingMethodBodyVisitor.d__3.MoveNext()

Details

  • Product in use: VS extension
  • Version in use: 8.1.6.0
  • Did you see it working in a previous version, which? no
@docfresh docfresh added the VB -> C# Specific to VB -> C# conversion label Aug 1, 2020
@GrahamTheCoder
Copy link
Member

Thanks for the report. There isn't quite enough context for me to immediately reproduce the issue.
If you have time, could you try removing various bits within the foreach loop, converting the single file and see what the minimum needed to break it is? Thanks

@docfresh
Copy link
Author

docfresh commented Aug 3, 2020

Here you go -- the class file with its members, a constructor, and the offending function. I could reproduce the bug by adding this file to a WinForms VB.NET project, and attempting a convert.

I suspect its because of the way the foreach types are declared as form members, but I'm not sure.

ConWinOrders.zip

@docfresh
Copy link
Author

docfresh commented Aug 3, 2020

Here is a VB project ready to convert / throw the bug.
convertbug2a.zip

@GrahamTheCoder
Copy link
Member

Thanks!

@GrahamTheCoder
Copy link
Member

GrahamTheCoder commented Aug 4, 2020

I reproduced a similar looking error. Using a class member as the foreach variable should be supported in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants