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#: InvalidOperationException during conversion #934

Closed
CardenInsurance opened this issue Aug 4, 2022 · 1 comment
Closed

VB -> C#: InvalidOperationException during conversion #934

CardenInsurance opened this issue Aug 4, 2022 · 1 comment
Labels
VB -> C# Specific to VB -> C# conversion

Comments

@CardenInsurance
Copy link

VB.Net input code

Using db As New PRIMEEntities

	Dim result As Dictionary(Of Export_File_Key, Date) = (From log In db.ImportARMTECHLogs
                  Where log.Action = ImportActionType_ARMTECH.Apply_Temp_Tables_To_Production And log.Is_Success = True
                  Group log By log.Reinsurance_Year, log.Export_Data_Type, WithShapes = log.Original_Filename.ToUpper.Contains("WITHSHAPES") Into g1 = Group
                  Select g1.OrderByDescending(Function(x) x.Date_From_Filename)
                  .FirstOrDefault())
                  .ToDictionary(Of Export_File_Key, DateTime)(Function(x) New Export_File_Key() With {
                  .Reinsurance_Year = x.Reinsurance_Year,
                  .Export_Data_Type = x.Export_Data_Type,
                  .With_Shapes = x.Original_Filename.ToUpper.Contains("WITHSHAPES")
                  }, Function(y) y.Date_From_Filename)

	Return result
End Using

Erroneous output

using (var db = new PRIMEEntities())
            {

                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__70.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 log In db.ImportARMTECHLogs
                                                                                                                 Where log.Action = ImportActionType_ARMTECH.Apply_Temp_Tables_To_Production And log.Is_Success = True
                                                                                                                 Group log By log.Reinsurance_Year, log.Export_Data_Type, WithShapes = log.Original_Filename.ToUpper.Contains("WITHSHAPES") Into g1 = Group
                                                                                                                 Select g1.OrderByDescending(Function(x) x.Date_From_Filename).FirstOrDefault()
                                                */
                            .ToDictionary<ImportARMTECHLog, Export_File_Key, DateTime>(x => new Export_File_Key()
                            {
                                Reinsurance_Year = x.Reinsurance_Year,
                                Export_Data_Type = x.Export_Data_Type,
                                With_Shapes = x.Original_Filename.ToUpper().Contains("WITHSHAPES")
                            }, y => y.Date_From_Filename);


                return result;
            }

Details

  • Product in use: e.g. VS extension
  • Version in use: 9.0.3.0
@CardenInsurance CardenInsurance added the VB -> C# Specific to VB -> C# conversion label Aug 4, 2022
@GrahamTheCoder
Copy link
Member

I'll consolidate this with #298 since I think it's the same issue.
Query syntax is definitely a weak area for the converter since it's essentially two whole extra languages and I keep thinking the whole area may need a fresh approach. Lots of examples are the key to improving so thanks!

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