You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System;using System.Diagnostics;using System.IO;using System.Windows.Forms;namespaceCMM_AutoPostProcess{publicclassGetTargets2{publicvoidTargets(stringfile){stringJobID;intFileNameStart;intFileNameLength;introw,i;boolclosed;boolautoProcess;stringAutofile;string?L;stringJob;FileNameStart= file.LastIndexOf('\\')+1;FileNameLength= file.Length -FileNameStart;JobID= file.Substring(FileNameStart, FileNameLength);// Convert to UppercaseJobID= JobID.ToUpper();// Find JobID in list and then extract relevant informationi=1;row=0;do{try{Job="Test";if(JobID.Contains(Job)){row=i;autoProcess=true;}i++;}catch{//Safe to skip}}while(row==0);conststringtarget="Mesh";autoProcess= File.Exists(target);if(autoProcess){Autofile="Post.txt";varsw=new StreamWriter(Autofile);
sw.WriteLine("$TEXT");
sw.WriteLine("Endjob");
sw.WriteLine("Execute");
sw.WriteLine("$TXTEND");
sw.Close();if(File.Exists(Autofile)){varreader=new StreamReader(Autofile);closed=false;do{L= reader.ReadLine();if(L=="$TXTEND"){closed=true;}}while(!closed&& reader.Peek()!=-1);
reader.Close();StreamWritertw=new("runfile.txt");stringmsg;try{if(closed){
tw.WriteLine("Running software for "+JobID);stringAppRef= Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),@"Microsoft\Windows\Start Menu\Programs\Zeiss BG VisionCare\CMMProcess.appref-ms");if(File.Exists(AppRef)){new Process
{StartInfo=new ProcessStartInfo(AppRef){UseShellExecute=true,CreateNoWindow=true,Arguments=Autofile}}.Start();}else{msg="Cannot find click-once application "+AppRef;
tw.WriteLine(msg);
MessageBox.Show(msg);}}}catch(Exceptionex){
MessageBox.Show(ex.ToString());}finally{
tw.Close();}}}else{varsw=new StreamWriter("PostError.txt");
sw.WriteLine("Did not manage to find any target information");
sw.Close();}}}}
Erroneous output
ImportsSystemImportsSystem.DiagnosticsImportsSystem.IOImportsSystem.Windows.FormsNamespaceCMM_AutoPostProcessPublicClassGetTargets2PublicSubTargets(fileAsString)DimJobIDAsStringDimFileNameStartAsIntegerDimFileNameLengthAsIntegerDimrow,iAsIntegerDimclosedAsBooleanDimautoProcessAsBooleanDimAutofileAsStringDimLAsString?DimJobAsStringFileNameStart=file.LastIndexOf("\"c)+1FileNameLength=file.Length-FileNameStartJobID=file.Substring(FileNameStart,FileNameLength)' Convert to UppercaseJobID=JobID.ToUpper()' Find JobID in list and then extract relevant informationi=1row=0DoTryJob="Test"IfJobID.Contains(Job)Thenrow=iautoProcess=TrueEndIfi+=1Catch'Safe to skipEndTryLoopWhilerow=0Consttarget="Mesh"autoProcess=IO.File.Exists(target)IfautoProcessThenAutofile="Post.txt"Dimsw=NewStreamWriter(Autofile)sw.WriteLine("$TEXT")sw.WriteLine("Endjob")sw.WriteLine("Execute")sw.WriteLine("$TXTEND")sw.Close()IfIO.File.Exists(Autofile)ThenDimreader=NewStreamReader(Autofile)closed=FalseDoL=reader.ReadLine()IfEquals(L,"$TXTEND")Thenclosed=TrueEndIfLoopWhileNotclosedAndAlsoreader.Peek()<>-1reader.Close()''' Cannot convert LocalDeclarationStatementSyntax, System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.''' at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration)''' at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)''' at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)''' at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)''' ''' Input:''' System.IO.StreamWriter tw = new("runfile.txt");''' ''' DimmsgAsStringTryIfclosedThentw.WriteLine("Running software for "&JobID)DimAppRef=Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),"Microsoft\Windows\Start Menu\Programs\Zeiss BG VisionCare\CMMProcess.appref-ms")IfIO.File.Exists(AppRef)ThenCallNewProcessWith{.StartInfo=NewProcessStartInfo(AppRef)With{.UseShellExecute=True,.CreateNoWindow=True,.Arguments=Autofile}}.Start()Elsemsg="Cannot find click-once application "&AppReftw.WriteLine(msg)MessageBox.Show(msg)EndIfEndIfCatchexAsExceptionCallMessageBox.Show(ex.ToString())Finallytw.Close()EndTryEndIfElseDimsw=NewStreamWriter("PostError.txt")sw.WriteLine("Did not manage to find any target information")sw.Close()EndIfEndSubEndClassEndNamespace
Expected output
Intheaboveyoucanseeaproblemconvertingnestedconstructorsjustafter"Call New Process With".EasytofixwithalocalvariableforStartInfoandun-nestingconstructors.ThereisalsoaproblemwithconvertingSystem.IO.StreamWritertw=new("runfile.txt");
butthatisverynewsyntax.Theexceptionsseemtorelatetothisproblemwherethereisnotypeafterthenew.
Details
Product in use: VS extension
Version in use: 9.2.5.0 VS2022
Did you see it working in a previous version, which? First try on this code
Converting 1 files...
Phase 1 of 2:
MediaLibCore\Util\GetTarget2.cs - conversion started
MediaLibCore\Util\GetTarget2.cs - conversion has errors:
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration)
at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
Phase 2 of 2:
MediaLibCore\Util\GetTarget2.cs - simplification started
MediaLibCore\Util\GetTarget2.cs - simplification has errors:
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration)
at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
Input code
Erroneous output
Expected output
Details
Converting 1 files...
Phase 1 of 2:
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration)
at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
Phase 2 of 2:
System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration)
at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node)
at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node)
Code conversion completed with 1 error
1 files have been written to disk.
Please report issues at https://github.com/icsharpcode/CodeConverter/issues
The text was updated successfully, but these errors were encountered: