Skip to content

VB -> C#: Cannot convert QueryExpressionSyntax, System.InvalidOperationException: Sequence contains more than one element when converting a specific Linq query #1172

@wizzardmr42

Description

@wizzardmr42

VB.Net input code

Dim fields = (From v In _DisplayFields Select Value = v, Name = [Enum].GetName(GetType(Field), v) Order By Value Ascending).ToArray

note that the following works fine, which is functionally identical:
Dim fields = _DisplayFields.Select(Function(v) New With {.Value = v, .Name = [Enum].GetName(GetType(Field), v)}).OrderBy(Function(x) x.Value).ToArray

Erroneous output

        var fields = default

#error Cannot convert QueryExpressionSyntax - see comment for details
/* Cannot convert QueryExpressionSyntax, System.InvalidOperationException: Sequence contains more than one element
at System.Linq.Enumerable.Single[TSource](IEnumerable1 source) at ICSharpCode.CodeConverter.CSharp.QueryConverter.<ConvertSelectClauseAsync>d__34.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at ICSharpCode.CodeConverter.Common.EnumerableExtensions.<YieldAsync>d__61.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.QueryConverter.d__27.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.QueryConverter.d__9.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.QueryConverter.d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.QueryConverter.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.ExpressionNodeVisitor.d__68.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at ICSharpCode.CodeConverter.CSharp.CommentConvertingVisitorWrapper.d__12`1.MoveNext()

   Input:
   From v In _DisplayFields Select Value = v, Name = [Enum].GetName(GetType(Field), v) Order By Value Ascending
    */
   .ToArray();

Expected output

var fields = (from v in _DisplayFields select new {Value = v, Name = Enum.GetName(typeof(Field), v)} orderby Value).ToArray();

Details

VS extension 9.2.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    VB -> C#Specific to VB -> C# conversionexception caughtAn exception is caught (and stacktrace provided)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions