Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

VB -> C#: InvalidOperationException caused by LINQ GroupBy with multiple properties

オープン
#1,014 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
csharp
領域
tooling

調査の方向性

issue 内の QueryConverter のスタックトレースから始め、複数の GroupBy プロパティを使用する VB LINQ クエリを再現します。失敗に関係するサブクエリおよびクエリセグメントの変換を追跡します。再現ケースが InvalidOperationException なしで変換され、グループ化されたクエリに対して有効な C# を生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

VB -> C#
VB.Net input code
Public Class ConversionTest4
    Private Class MyEntity
        Property FavoriteNumber As Integer
        Property FavoriteColor As String
        Property Name As String
    End Class
    Private Sub BugRepro()

        Dim entities As New List(Of MyEntity)

        Dim result As IEnumerable(Of String) = From e In entities
                                               Group e By e.FavoriteNumber, e.FavoriteColor Into g1 = Group
                                               Select g1.FirstOrDefault().Name

    End Sub
End Class
Erroneous output
public class ConversionTest4
    {
        private class MyEntity
        {
            public int FavoriteNumber { get; set; }
            public string FavoriteColor { get; set; }
            public string Name { get; set; }
        }
        private void BugRepro()
        {

            var entities = new List<MyEntity>();

            var result = 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](IEnumerable`1 source)
            at ICSharpCode.CodeConverter.CSharp.QueryConverter.<ConvertSubQueryAsync>d__15.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at ICSharpCode.CodeConverter.CSharp.QueryConverter.<ConvertQueryWithContinuationAsync>d__14.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at ICSharpCode.CodeConverter.CSharp.QueryConverter.<ConvertQuerySegmentsAsync>d__12.MoveNext()
         --- End of stack trace from previous location where exception was thrown ---
            at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
            at ICSharpCode.CodeConverter.CSharp.QueryConverter.<ConvertClausesAsync>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.<VisitQueryExpression>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.<ConvertHandledAsync>d__8`1.MoveNext()

         Input:
         From e In entities
                                                        Group e By e.FavoriteNumber, e.FavoriteColor Into g1 = Group
                                                        Select g1.FirstOrDefault().Name

          */;

        }
    }
Details
  • Product in use: VS extension
  • Version in use: 9.2.2.0
  • This is a simplified repro code
  • I believe this exception happens because the "Group e By" line contains multiple properties to group on.
主要言語
C#
スター
913
フォーク
243
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

icsharpcode/CodeConverter のほかの issue

icsharpcode/CodeConverter の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。