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#: Exception converting linq expression with OrderBy and Distinct #635

Closed
KunzeAndreas opened this issue Sep 24, 2020 · 1 comment
Labels
exception caught An exception is caught (and stacktrace provided) VB -> C# Specific to VB -> C# conversion

Comments

@KunzeAndreas
Copy link

Input code

' works fine
 Dim list = New List(Of String)
 Dim listSorted = From x In list Order By x
 Dim listDistinct = From x In listSorted Distinct
' exception
Dim listSortedDistinct = From x In list Order By x Distinct

### Erroneous output

#error Cannot convert LocalDeclarationStatementSyntax - see comment for details
            /* Cannot convert LocalDeclarationStatementSyntax, System.InvalidCastException Das Objekt des Typs "Microsoft.CodeAnalysis.CSharp.Syntax.EmptyStatementSyntax" kann nicht in Typ "Microsoft.CodeAnalysis.CSharp.Syntax.LocalFunctionStatementSyntax" umgewandelt werden.
               at System.Linq.Enumerable.<CastIterator>d__97`1.MoveNext()
               at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)
               at ICSharpCode.CodeConverter.CSharp.MethodBodyExecutableStatementVisitor.<VisitLocalDeclarationStatement>d__31.MoveNext()
            --- End of stack trace from previous location where exception was thrown ---
             at ICSharpCode.CodeConverter.CSharp.HoistedNodeStateVisitor.<AddLocalVariablesAsync>d__6.MoveNext()
           --- End of stack trace from previous location where exception was thrown ---
               at ICSharpCode.CodeConverter.CSharp.CommentConvertingMethodBodyVisitor.<DefaultVisitInnerAsync>d__3.MoveNext()

### Details
* Product in use: VS extension 
* Version in use: 8.1.8.0
* Did you see it working in a previous version, which? No
@KunzeAndreas KunzeAndreas added the VB -> C# Specific to VB -> C# conversion label Sep 24, 2020
@GrahamTheCoder
Copy link
Member

Thanks for the report. The code in this area of the converter is a little convoluted, but debugging your test case should hopefully yield a straightforward enough fix. I'm a bit busy right now, but let me know if you're interested in having a go and I'll do my best to help out

@GrahamTheCoder GrahamTheCoder added the exception caught An exception is caught (and stacktrace provided) label Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exception caught An exception is caught (and stacktrace provided) VB -> C# Specific to VB -> C# conversion
Projects
None yet
Development

No branches or pull requests

2 participants