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

Aperta
#1,172 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
devtools

Direzione di ricerca

Usa la query VB segnalata come riproduzione e inizia da QueryConverter.ConvertSelectClauseAsync, identificato nello stack trace. Confronta la sua conversione delle clausole Select e Order By con l'output C# previsto, quindi verifica che la query venga convertita senza l'errore Sequence contains more than one element.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

exception caught VB -> C#
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

Lingua principale
C#
Stelle
913
Fork
244
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di icsharpcode/CodeConverter

Tutte le issue di icsharpcode/CodeConverter

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.